Answer by lericr for How to reuse an iterator in different functions?
Not really an answer, and maybe pedantic, but nevertheless...You probably don't want to do that at all (although the Evaluate suggestions work fine if this is a "quick and dirty" situation). It is...
View ArticleAnswer by Goofy for How to reuse an iterator in different functions?
Version 1i = 13: (* check evaluation leakage *)ClearAll[iter];SetAttributes[iter, HoldAll];iter[cmd_[f_]] := cmd[f, {i, 0, 10}];iter@Table[i]iter@Table[i^2]Sum[f[i]] // iterVersion 2i = 13: (* check...
View ArticleAnswer by eldo for How to reuse an iterator in different functions?
iter = {i, 0, 10};Since Table"holds" all its arguments you must Evaluate iterTable[i^2, Evaluate @ iter]{0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100}Attributes[Table]{HoldAll, Protected}A simple example...
View ArticleHow to reuse an iterator in different functions?
How can I reuse iterators?For example, instead ofTable[i, {i,0,10}]Table[i^2, {i,0,10}]Table[f[i], {i,0,10}]write something likeiter={i,0,10}Table[i, iter]Table[i^2, iter]Sum[f[i], iter]
View Article
More Pages to Explore .....