A function is really a mathematical idea. In Mathematica, we can represent, or denote, a function in a few ways. But Mathematica is really working with expressions.
Map[a, {b, c, d}]
{a[b], a[c], a[d]}
Mathematica doesn't know that this is meaningless. It's just applying its rules for transforming expressions.
Map[#[x] &, {a, b, c}]
{a[x], b[x], c[x]}
The way Function works (the # and & are just syntactic sugar for Function), is to just replace the argument slots with the values passed in as arguments. And Map does this for every element in a list (well, more accurately, every element at the first level of an expression).
Map[#[x] &, {Sin, Cos, Tan}]
{Sin[x], Cos[x], Tan[x]}
Sin, Cos, and Tan aren't functions, they're just symbols to which evaluation rules are attached. In this case, there are no rules that take us further than just Sin[x] et al, so it stops there and that's the result.
Map[#[{2, b}] &, {Reverse}]
If we could pause evaluation, we could see this: {Reverse[{2, b}]}
. But there are rules that still apply to this expression, so we continue on, eventually arriving at {{b, 2}}
.
Can anybody help me put think about this in a simple way?
I don't know if you'll find it simple, but try to remember that we apply the concept function to our expressions, but expressions aren't inherently functions. Functions are abstract, but we want to compute as if they're real, so we create expressions that work as if they were functions. This is very useful, but it's just pretending.
Reverse
is a function that is being passed as a parameter value to the pure function#[{2,b}]&
. The#
(reallySlot[1]
) will be replaced by the 1st parameter so the pure function becomesReverse[[{2,b}]
and then is evaluated. Functions can be parameters of functions. $\endgroup$foo = Reverse
and then replaceReverse
withfoo
in your original expression. $\endgroup$