NetLogo / Tortoise

Compiler and runtime engine for NetLogo models that runs in JavaScript 🐢
https://netlogoweb.org
Other
56 stars 27 forks source link

Let-vars created by running strings in procedures not scoped or cleared correctly #227

Closed qiemem closed 2 years ago

qiemem commented 3 years ago

To reproduce:

  1. Create a procedure that runs a string that uses a let-var:
to foo
  run "let a 1"
end
  1. Execute that procedure twice. Result:
observer> foo
observer> foo
ERROR: There is already a local variable here called A

Alternatively:

  1. Create a procedure that runs two string that introduce a let-var of the same name:
to foo
  run "let a 1"
  run "let a 2"
end
  1. Execute that procedure once (same result).

As far as I can tell, this is because the let-vars (incorrectly) bind to the procedure, not the execution context of the string (and are also not cleared between executions of the procedure).

This problem is kind of a regression, in the sense that no error occurred before, and the code would execute and behave as expected in most cases. However, I think that the binding was still wrong before, it just wasn't erroring (but now is because of 2dcc4b2563541e23d3ffbe808ff673f145254288).

In desktop NetLogo, each string is given its own nesting level of scope. For instance, this procedure works in NetLogo desktop but not NetLogo Web:

to foo
  run "run \"let a 1\" run\"let a 2\""
end