I am trying to use a Table to create the following object:


The obvious doesn't work,

Table[f[#, j] &, {j, 1, 3}]

It gives:

{f[#1, j] &, f[#1, j] &, f[#1, j] &}

leaving the j unevaluated. I assume that's due to the HoldAll attribute of Function. How do I get around this? Thanks

  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Feb 2 '16 at 23:36
  • $\begingroup$ Also see: (56412) $\endgroup$ – Mr.Wizard Feb 3 '16 at 14:15

Some possibilities:

Table[With[{j = j}, f[#, j] &], {j, 3}]
Function[{j}, f[#, j] &] /@ Range[3]
f[#, j] & /. List /@ Thread[j -> Range[3]]

This seems to work.

Table[(f[#, i] &) /. i -> j, {j, 1, 3}]
(* {f[#1, 1] &, f[#1, 2] &, f[#1, 3] &} *)

Note that #1 and # are equivalent.


Not the answer you're looking for? Browse other questions tagged or ask your own question.