Closed studej closed 10 years ago
the primitives (IF) are special cases. You can declare a script variable inside an IF-block. I'm not sure whether I want to address this...
Hmm yes I see. I created custom "if block" and then variable was not accessible. From your post @jmoenig it seems that user should not be able to declare script variable in IF block, did I understand it? So script variable is a variable only on level of script/custom or anonymous block? I was thinking that script variable == local variable.
No, it's okay to declare script vars inside primitive loops and conditionals, but, in that case they'll be accessible in the whole "script", not just within the enclosing C-shaped slot. Script vars are temporary variables at the script level.
Apparently we're supposed to think of SCRIPT VARIABLES as something executable, not as a declaration. "Create a new variable right now with the current script as its scope." (This is in answer to the first picture above.) That's what Berkeley Logo does, so it must be right! :-)
"Create a new variable right now with the current script as its scope." (This is in answer to the first picture above.) That's what Berkeley Logo does, so it must be right! :-)
Yes, this makes sense to "current scope" doesn't always make sense in the context of a loop / conditional. There's plenty of cases where block level scoping is insanely convenient.
Not saying Snap! is wrong, and I agree with keeping it simple, but there are other options.
Is that intention that I can declare new script variable by using the same indentifier in the same or nested scope? Imho following example should not work and should show error.
There is an obvious collision.
@jmoenig commented https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/issues/157
It is true that I can check which variable is available in the context: (variable "a" is not accesible and also should not exist anymore after we left body of if block)
...but you can do this:
How is it possible that script variable declared in nested scope is available to outer scope? It should not exists at all.