Yep, the scoping rules and closure behavior are shamelessly stolen from Scheme. Those guys seem to know what they're doing :-)
On Thu, Feb 5, 2015 at 12:08 PM, Michael Francis <[email protected]> wrote: > thanks - so it take the scheme approach to closures. The let keyword > allows the inverse. > > On Thursday, February 5, 2015 at 10:36:37 AM UTC-5, Mauro wrote: >> >> Yes, this is expected. Have a look at the scope section of the manual, >> it also has examples on how to get the behaviour (I suspect) you want. >> >> On Thu, 2015-02-05 at 16:26, Michael Francis <[email protected]> wrote: >> > function test() >> > x = 2 >> > f = (()->x + 3) >> > println( f() ) # Prints 5 Yeh! >> > x = 4 >> > println( f() ) # Prints 7 ??? >> > g = (()->(x=4)) >> > println( g() ) # Prints 4 Yeh, that should not be the same x >> > println( x ) # Oops seems it is the same X >> > println( f() ) # Yes seems there is one X here >> > end >> > >> > test() >> > >> > Prints - >> > >> > >> > - >> > >> > 5 >> > 7 >> > 4 >> > 4 >> > 7 >> > >> > >> > Is this the expected behavior for closures? it is not what I expected. >> > >> > This is in both 0.3.4 and 0.4.0-dev+3135 >> >>
