In the following example, why do these two calls to Apply
return different results?
list = {"a", "b"};
Apply[f, list]
Apply[f[#] &, list]
f[a, b]
f[a]
In contrast, when using Map
(which is a different function from Apply
), these two calls return results identical to each other:
list = {"a", "b"};
Map[f, list]
Map[f[#] &, list]
{f["a"], f["b"]}
{f["a"], f["b"]}
#
is short forSlot[1]
, which represents (only) the first argument. Also rememberTrace
orTracePrint
: On simple code, such asApply[f, list] // Trace
andApply[f[#] &, list] // Trace
, theTrace
gives a nice sequence that shows how an expression is evaluated. (TracePrint
shows more and is therefore both more complete and more complicated to follow.) $\endgroup$f
hasAttributes
, thenf[##] &
does not. In practice, this matters most whenf
has aHold*
attribute such asHoldAll
. [A better question might be what are the differences betweenf
andf[#] &
.] $\endgroup$