asteroid icon indicating copy to clipboard operation
asteroid copied to clipboard

implement 'nonlocal' keyword

Open lutzhamel opened this issue 4 years ago • 1 comments

The nonlocal command works analogous to the global command except that it will inspect the surrounding scopes rather than just the global scope. Example,

load system io.
function myfunc1 with none do
   let x = "John".
   function myfunc2 with none do
       nonlocal x.
       let x = "hello".
   end
   myfunc2().
   return x.
end

io @println (myfunc1()).

should print out hello.

lutzhamel avatar Feb 09 '22 01:02 lutzhamel

I am not quite sure we want this...this is only needed when writing nested function definitions where the nested function uses data from the surrounding function definition as non-local data. That is terrible programming and we should not support this kind of hacking.

lutzhamel avatar Aug 06 '22 15:08 lutzhamel