jrincayc / ucblogo-code

Berkeley Logo interpreter
https://people.eecs.berkeley.edu/~bh/logo.html
GNU General Public License v3.0
182 stars 34 forks source link

LOCAL for already-existing variable clobbers variable #154

Open jasonsikes opened 1 year ago

jasonsikes commented 1 year ago

Is this a bug?

? to g
> localmake "foo "bar
> local "foo
> show :foo
> end
g defined
? g
foo has no value  in g
[show :foo]

I can see how this happens. LOCAL creates a placeholder in the variable stack and assigns the value {nothing}. But if a value already exists should it be clobbered?

jrincayc commented 1 year ago

Hm, I am not sure. @brianharvey what are your thoughts?

brianharvey commented 1 year ago

Good question.

"If a variable already exists" is the wrong condition, though, since variables are inherited from any outer scope. So, if you were to change this, it'd have to be "if a variable of the same name has already been created in this procedure call..."

The current behavior has been the case right from the beginning of ucblogo, so if it's a bug it's a longstanding one. The manual is silent on the question. So I think it's okay to keep the current behavior, but I agree that the suggested change would be an improvement, just in case the LOCAL is inside a FOR loop or some such thing.