Responding to your updated question, which should probably be closed as a duplicate once someone takes the time to find the original: Evaluate
only works when it is the explicit head of an argument. In other words Evaluate[ . . . ]
must appear as one of the arguments of the Head who's Hold attribute you wish to override. You should read this paper, which teaches this among many other useful things:
As an example consider these lines:
Hold[1 + 1, Evaluate[2 + 2]]
Hold[1 + 1, {Evaluate[2 + 2]}]
Hold[1 + 1, Evaluate @@ {2 + 2}]
Hold[1 + 1, 4]
Hold[1 + 1, {Evaluate[2 + 2]}]
Hold[1 + 1, Evaluate @@ {2 + 2}]
Note that only the first form evaluates. On lines two and three the Heads of the second arguments are List
and Apply
rather than Evaluate
.
A common method to get around this is to use With
to inject an expression into the body of the function:
With[{body = Slot /@ Range[19, 164, 29]}, {body} &]
% @@ Range[164]
{{#19, #48, #77, #106, #135, #164}} &
{{19, 48, 77, 106, 135, 164}}
If you want to evaluate the entire body every time you can just Apply
Function
to a List
of the components that form the Function
:
(Function @@ {{Slot /@ Range[19, 164, 29]}}) @@ Range[164]
{{19, 48, 77, 106, 135, 164}}