ucblogo-code
ucblogo-code copied to clipboard
LOCAL for already-existing variable clobbers variable
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?
Hm, I am not sure. @brianharvey what are your thoughts?
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.