-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG? blocks can partially defer execution #39
Comments
The block definitely grabbing the There doesn't seem to be a way of avoiding this. Probably one of many problems with this language... |
From my understanding of functional programming, closures don't change their behavior based on an external state. Rather, they have to be passed an argument for that value to be used. The entire reason functional programs need closures is because there is no global mutable state, and closures offer a shared mutable state in place of that global state. While brat is object oriented, and thus has global mutable state, proper closures shouldn't be affected by that state. Perhaps it could be fixed by prefixing the compiled Lua variable names with a unique id, such that brat variables with the same name don't compile to have the same name in lua if they have different scopes. For example: a global brat variable "foo" and a brat variable named "foo" in a closure compile like so:
|
I have misremembered what a closure is, that's my bad. Turns out closures persist things in their lexical scope even when called outside said scope. So the closures in brat are using the scope in which they are defined as their lexical scope. The refusal to override the "a" variable thus makes sense, as the value of a from the global scope is being stored in the closure, while the value of "b" is being inherited from the lexical scope. |
I'm trying to make a lisp-like
let
operator, I discovered unexpected behavior in how blocks are executed.Expected behavior: either execution of the
{p a + b}
block is deferred, and thus prints2
, or it is executed immediately and throws an error saying that b is undefined (since in that scope it is).Observed Behavior: the function prints
11
as ifa
used the value from outside the lexical object, but waited to get the value forb
.Is this unintended behavior? Or is there some rule I'm missing?
The text was updated successfully, but these errors were encountered: