# Syntax for Table with a pure function

I have:

g = #1^2 + a #2^3 / #1 &


Now I wish to make a Table evaluating this from 1 to 10

Table[ g, { #, 1, 10}]


fails.

What is the correct syntax?

Maybe Array is more suitable than Table for this task:

g = #1^2 + a #2^3/#1 &;
Array[g, {10, 10}]


You cannot use Slot (#) as an iterator. You have to apply an argument:

g = #1^2 + a #2^3/#1 &;
Table[g[i, i], {i, 1, 10}]

• Thanks to all for the helpful answers – CMoller Sep 20 '14 at 0:08

Map is another concise alternative:

g = #1^2 + a #2^3/#1 &;
g[#, #] & /@ Range


If you wish to iterate on the first argument from 1 to 10 to get a list of 10 functions, you can use

Table[With[{i = i}, g[i, #] &], {i, 1, 10}]
(* {g[1, #1] &, g[2, #1] &, g[3, #1] &, g[4, #1] &, g[5, #1] &,
g[6, #1] &, g[7, #1] &, g[8, #1] &, g[9, #1] &, g[10, #1] &} *)


If you want to iterate both arguments from 1 to 10 (on the diagonal), you can use Table as in halirutan's answer, or Array

Array[g[#, #] &, {10}]
(* {15, 60, 135, 240, 375, 540, 735, 960, 1215, 1500} *)


For iterating each of the two arguments separately you can use Array[g, {10, 10}] as in Karsten 7.'s answer, or

Table[g[i, j], {i, 10}, {j, 10}]
Table[g[i, j], {i, 10}, {j, 10}] ==Array[g, {10, 10}]
(* True *)