grol-io / grol

Go REPL Open Language
https://grol.io
Apache License 2.0
22 stars 2 forks source link

Reference object type: Allow mutations in upper scope, add back `:=` for forcing local scope variable creation; cache bug fix #206

Closed ldemailly closed 2 months ago

ldemailly commented 2 months ago

Fixes #207

Until now every capture of state was a copy, it was impossible to modify upper state without collaboration from the caller in term of assigning a result

We introduce capture by reference instead of by value by default now. And a:=a to make a local copy (or only use the function arguments which are always local)

a = 2
()=>{a=3}()
a // now 3
ldemailly commented 2 months ago

diff is now shorter, no more a million mechanical peppering of object.Value(x) in front of x.(object.Type)

instead we try to decide to use Eval() when we need to unwrap the refererences (which is a few more place and also somewhat mechanical, see todo)