I evaluated
Table[#[[i]] &, {i, 1, 5}]
and got
{#1[[i]] &, #1[[i]] &, #1[[i]] &, #1[[i]] &, #1[[i]] &}
what I did expect was
{#1[[1]] &, #1[[2]] &, #1[[3]] &, #1[[4]] &, #1[[5]] &}
I always assumed Table would just replace the expression with a list of replacement rules similar to what ReplaceAll would do given a list of rules.
ReplaceAll[#[[i]] &, {Thread[i->Range[5]]}//Transpose]
which gives
{#1[[1]] &, #1[[2]] &, #1[[3]] &, #1[[4]] &, #1[[5]] &}
Can someone please explain the difference?
Function // AttributesnotTable's. But I agree this question should be closed, probably as a duplicate. – Kuba Mar 05 '15 at 08:15#[[i]] & /. i -> 1. Table has the HoldAll attribute as Nasser and rasher pointed out. ButReplaceAll[ Unevaluated[#[[i]] &], {Thread[i -> Range[5]]} // Transpose]still yields the result with the i's replaced. Where is the difference between my approach and Table? – Max1 Mar 05 '15 at 09:21