When nothing is defined, what does Mathematica take for #1?
In the example Array[#1 + 2 #2 &, {4, 4}]
, the function #1 + 2 #2 &
is not being called. Rather, it is being passed itself as an argument to Array
. That is why there are no arguments within square brackets following it.
The documentation of Array
tells us that a function passed in this way will be called once for every element in the result array. So ultimately the function will be called many times, each call receiving a set of array indices and expected to return a value for the corresponding array element.
What numbers does it take for #1 and #2?
The Array
expression is creating a two-dimensional matrix so the arguments to the function will be the row and column indices into that matrix. That is, #1
is the row number and #2
is the column number.
We can see this more directly with an expression like this:
Array[a[#1, #2] &, {4, 4}] // MatrixForm

If we compare this matrix to the result shown below for the original expression, then we will see that each element in the lower picture is equal to the sum of the row index plus two times the column index from the upper picture:
Array[#1 + 2 #2 &, {4, 4}] // MatrixForm

You will sometimes see expressions like a[#1, #2]
written as a[#, #2]
or a[##]
. In the former case, #
is a short form of #1
. In the latter case, ##
can be read as "all arguments".
When nothing is defined, what does Mathematica take for #1? (Redux)
If a function is actually called with too few arguments, then error messages will be issued. For example:
f = #1 + #2&
f[]

If too many arguments are specified, the excess arguments are quietly ignored:
f[1, 3, 5, 7]
(* 4 *)
Array[#&,3]
$\endgroup$ – AccidentalFourierTransform Nov 8 '19 at 22:48#1
and#2
are each filled with 1. $\endgroup$ – Brett Champion Nov 8 '19 at 22:56Array[]
. The first argument ofArray[]
is a function or the name of a function, taking as many arguments as the second and subsequent arguments specify nesting. It is not the case that "nothing is defined". $\endgroup$ – Eric Towers Nov 9 '19 at 21:58