Hacker News new | ask | show | jobs
by leafo 4973 days ago
I've thought about this. It doesn't make as much sense in Lua. An iterated variable it gets it's own local assignment for each iteration. The variable isn't shared like JavaScript:

http://moonscript.org/compiler/#14

Here I create 10 functions closed on the loop value. Then I loop over them and call them all. In JavaScript this would print 10 10 times, but in Lua we get the 1 through 10.

1 comments

Cool! I was aware that variable reassignment didn't carry over in for loops, but I didn't know that the variables in each iteration were independent.

Keep up the good work!