# Array function and slot

I am trying to make an Array depending on a function, and I saw that Slotis useful for my situation. There are examples described in https://reference.wolfram.com/language/ref/Array.html?view=all that I'm trying to mimic, but in a more complicated situation.

So, I wrote the following:

Array[g[Slot[1] / 10 + I*Slot[2]/10, Slot[3]*10], {10, 10, 10}]

but instead of actually evaluating the code, it just leaves the Slots unevaluated and just literally prints things like 10 Slot[3] [1, 1, 1]. This even happens with a very simple function, for instance:

g[z_, n_] := n

How can I actually get Mathematica to actually evaluate the slots?

• If you want to learn about programming in Mathematica, I highly recommend Leonid Shifrin's amazing book. Aug 14, 2020 at 6:35
• Array[Function[g[Slot[1]/10 + I*Slot[2]/10, Slot[3]*10]], {10, 10, 10}] Aug 14, 2020 at 12:16

As explained in Tutorial: Pure Functions (tutorial/FunctionalOperations#17469) you need to finalize the definition of a pure function using the ampersand & character.

For instance, a simplified example would be

Array[g[Slot[1]] &, 5]
(*{g[1],g[2],g[3],g[4],g[5]}*)


In your case you can do

Array[g[Slot[1]/10 + I*Slot[2]/10, Slot[3]*10] &, {10, 10, 10}]


Note that Slots are usually written more readably as #n, i.e.

Array[g[#1/10 + I*#2/10, #3*10] &, {10, 10, 10}]

• Thanks, missed the & symbols in the examples, and now I see when I put that in, the #n actually looks like the green italic font instead of just red font without the & (which is why I used 'Slot' in the first place)
– Max
Aug 14, 2020 at 6:38
• @Max notice also as mentioned by cvgmt in comments above that you can wrap with Function to use the Slots. Aug 15, 2020 at 1:00