static Void main()
{
a := 15
b := [1,3,5,7,9]
b.each |val| { if (val > 6) { a = val } echo("val is $val, a is $a") }
echo("a is $a")
}
into a class and run it, I see:
val is 1, a is 15
val is 3, a is 15
val is 5, a is 15
val is 7, a is 7
val is 9, a is 9
a is 9
However, if I type every line (well, not the static Void... line or the braces) into fansh, I see the val is... lines, but at the end, a is 15. Expected behavior?
ivanFri 22 Oct 2010
I saw this issue earlier, here's even shorter example which illustrates the problem:
fansh> i := 0
0
fansh> 2.times { echo(i++) }
0
1
fansh> i
0
This happens because of the way fansh works - generally speaking it maintains a global scope of variables and compiles every command its own pod which gets a copy of global scope, but then after execution this local scope is not being merged back to global scope.
brianFri 22 Oct 2010
Yeah unfortunately is just the shortcuts we take to make fansh to work - essentially what it is doing is generating a script each time, then pulling out all the locals and storing them into a map.
yachris Thu 21 Oct 2010
Hello,
Just curious about this.
If I put:
into a class and run it, I see:
However, if I type every line (well, not the
static Void...
line or the braces) into fansh, I see theval is...
lines, but at the end, a is 15. Expected behavior?ivan Fri 22 Oct 2010
I saw this issue earlier, here's even shorter example which illustrates the problem:
This happens because of the way fansh works - generally speaking it maintains a global scope of variables and compiles every command its own pod which gets a copy of global scope, but then after execution this local scope is not being merged back to global scope.
brian Fri 22 Oct 2010
Yeah unfortunately is just the shortcuts we take to make fansh to work - essentially what it is doing is generating a script each time, then pulling out all the locals and storing them into a map.