I'm pretty sure that analogous questions have been asked here a zillion of times, but...
I think it is pretty straightforward from the code what I expect it to give:
oplist[] := Module[{op, list = {}, k},
For[k = 1, k <= 3, k++,
AppendTo[list, Function[x, x^k]];
];
For[k = 4, k <= 5, k++,
AppendTo[list, Function[x, x^k]];
];
Return[list];
];
list = oplist[];
For[k = 1, k <= Length[list], k++,
Print[list[[k]][a]];
];
Instead of a, a^2, a^3...
I have a^6, a^6, a^6...
I guess, it's something about pointers/links/evaluating at the moment when smth is called.
I tried replacing x^k
with x^Evaluate[k]
, but this does not help either.
oList = With[{k = #}, #^k &] & /@ Range@5
which can then be invoked withThrough@oList@a
. $\endgroup$