Message Boards Message Boards

0
|
2475 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

A HoldInherit option or equivalent?

Hi folks,

One thing I have noticed and gotten a little frustrated with recently is the behaviour of higher order functions such as Map[] when working on functions with Hold properties.

In the statement Map[f,{a,b,c}], if f[] has the property HoldFirst it will effectively be disregarded because Map will evaluate the arguments before passing them to f. This means that f[a], f[b], f[c] and Map[f,{a,b,c}] can have different results which is a bit of a nightmare for verifying functionality.

Is there any way to specify a HoldInherit or other property which states that a function that inputs another function should copy the holding behaviour of that other function?

POSTED BY: Mark Green

You can of course set some UpValues but I would not go this way as it may be tricky and long before you get something really general.

You can always use Unevaluated:

a = b = c = 1;
Map[Hold, Unevaluated@{a, b, c}]
{Hold[a], Hold[b], Hold[c]}
POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract