Function (&)

WMA link


Function[body]

body &

represents a pure function with parameters #1, #2, etc.

Function[{$x_1$, $x_2$, ...}, body]

represents a pure function with parameters $x_1$, $x_2$, etc.

Function[{$x_1$, $x_2$, ...}, body, attr]

assume that the function has the attributes attr.

You can use Function with named parameters:

Parameters are renamed, when necessary, to avoid confusion:

Slots in inner functions are not affected by outer function application:

In the evaluation process, the attributes associated with an Expression are determined by its Head. If the Head is also a non-atomic Expression, in general, no Attribute is assumed. In particular, it is what happens when the head of the expression has the form:

``Function[body]``
or:
``Function[vars, body]``

Notice that Hold in the body prevents the evaluation of $1+x$, but not the evaluation of $1+1$. To avoid that evaluation, of its arguments, the Head should have the attribute HoldAll. This behavior can be obtained by using the three arguments form version of this expression:

In this case, the attribute HoldAll is assumed, preventing the evaluation of the argument $1+1$ before passing it to the function body.

Slot