1

How to make Array as in following example but without list variable as first argument, but only as last postfix argument ?

list = {100, 200, 300, 400, 500};
Array[list[[#]] &, Length[#]] &@list

Expected result:

{100, 200, 300, 400, 500}

EDIT: I'm expect 1st argument in the form body &, and not something like Function[x, body] or definition of new nonpure function.

Dragutin
  • 920
  • 5
  • 14
  • I would just write list = {100, 200, 300, 400, 500}; f[n_] := list[[n]]; Array[f, Length@list] and it is simpler also :) – Nasser Nov 20 '17 at 22:23

1 Answers1

3

This is basically a duplicate of pure functions in nested select. Applying the accepted answer to your question:

list = {100, 200, 300, 400, 500};
Array[Function[x, #[[x]]], Length[#]]& @ list

{100, 200, 300, 400, 500}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355