ucblogo-code icon indicating copy to clipboard operation
ucblogo-code copied to clipboard

LOCAL for already-existing variable clobbers variable

Open jasonsikes opened this issue 2 years ago • 2 comments

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?

jasonsikes avatar Feb 03 '23 01:02 jasonsikes

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

jrincayc avatar Feb 03 '23 02:02 jrincayc

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.

brianharvey avatar Feb 03 '23 07:02 brianharvey