-
Notifications
You must be signed in to change notification settings - Fork 0
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
Our scoping is a little broken #22
Comments
This now allows the use of an arbitrary body, as can be seen in the following test: ``` (set! p 4) (while (<= p 10) (print "Pxx: %s" p) (set! p (+ p 1) true) ) ``` The new approach defines a local lambda, with a random name, and calls that recursively when the conditional is true. This closes #21, though we still need to use the three-argument form of (set!) as our scoping/environment is confused - that is tracked in #22.
There is a simple change that lets this specific example work:
But that still results in the following code not behaving as expected:
Basically entering a new function-body, or a lambda, or a (let, or a (let* scope will always mean that "set!" applies to that specific scope. I guess this means there's a question - when you set a variable in a scope, which exists in the parent, should we always forward to the parent? Or should we accept that the user needs to know about this issuue? I can see that if you always forward variable updates to the parent then we might have other surprises. Consider this code:
In that case it might be that the user deliberately wanted a local variable with the same name, and the global shouldn't be updated. If that is the case then it seems like we might want to allow the user to make the decision - and that probably means we end up with somethign like our extra-argument-to-set! functionality. So:
I'm torn .. |
There is a problem with scoping which can be revealed by this snippet:
Specifically the "set! n" should update the value of the "n" variable inside the let-scope, but doesn't unless the "true" parameter is added.
There are three scopes here:
(let*
binding.There's something not quite right about the effects when the function/let scope overlap.
The text was updated successfully, but these errors were encountered: