Closed chochos closed 9 years ago
What gets captured or not is a long story in every language. In this case c
is defined once in the loop and overridden at each iteration, so there's only a single binding that can be captured and it will hold the last value written to it after the loop is done. That's pretty well-defined in JS, and for loops and capture are a common gotcha in many languages. That's not the case in LISP because there's no iteration: it's only iteration using recursion, so you effectivement get an brand new environment at each iteration, which you can capture and is immutable.
I found this while testing the SDK, particularly
ceylon.promise
. This code:prints this, then breaks:
It's trying to use
finished
as a function. But in every iteration,c
should be a new function. Somehow the current item for the loop is not captured in the function created in every iteration.