Function
Function[body] or body& is a pure function. The formal parameters are # (or #1), #2, and so on.
Function[x, body] is a pure function with a single formal parameter x.
Function[
,
, ...
, body] is a pure function with a list of formal parameters.
Example: (# + 1)&[x]
.
Map[(# + 1)&,
x, y, z
]
.
When Function[body] or body& is applied to a set of arguments, # (or #1) is replaced by the first argument, #2 by the second, and so on. #0 is replaced by the function itself.
If there are more arguments supplied than #i in the function, the remaining arguments are ignored.
Function is analogous to
in LISP or formal logic.
The function body is evaluated only after the formal parameters have been replaced by arguments.
The named formal parameters
in Function[
, ...
, body] are treated as local, and are renamed
$ when necessary to avoid confusion with actual arguments supplied to the function.
Function is treated as a scoping construct (see Section A.3.8).
See The Mathematica Book on the web: Section 2.2.5.
See also: Apply.
Further Examples