1

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

{f[#,1]&,f[#,2],f[#,3]}

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

2 Answers2

3

Some possibilities:

Table[With[{j = j}, f[#, j] &], {j, 3}]
Function[{j}, f[#, j] &] /@ Range[3]
f[#, j] & /. List /@ Thread[j -> Range[3]]
march
  • 23,399
  • 2
  • 44
  • 100
2

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.

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156