Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: local vars in functions

From: rishioswal::yahoo at: 24-Apr-2002 12:04

--- Carl Read wrote:
> I like the idea and the syntax, but what happens > with the likes of > this... > > a: 10 > a:: 20 > a: 30 > > Does that produce an 'a in both the global and local > context? And if > so, does the third expression above change the local > or global value, > or both? >
Hi Carl R. here was my brainstorming... a: 10 this would produce an 'a in the global context a:: 20 this would produce an 'a in the local context. If we are in the global context, then they would be the same 'a. a: 30 if both of the above 'a were in the global context, then all three words are one and the same. Basically, in the global space, there is no difference in setting with a:: or a: My reasons for making the change in the language would be mostly due to convience in functions. * no need do declare local word in first block of a func or second block of a function * no need to pick up the mouse, scroll to the first block of a func, and add the local word and then scroll back and write your code (writing code will be more continious with ::) * less code and typing since there is no need to declare local words (okay..so there is hardly any saving but still...) *does not burden beginner. Beginner does not have to use or learn this syntax, but once they understand local vars, it is no harder to learn "::" than to learn the use of "/local" in the first block of a func. *Syntactically backwards compatible with rebol * can use in inner words also as i had shown in my previous example.. works n levels deep *can use in other things other than functions *perhaps gets rid of the need to know the other ways of creating locals ('use, /local, etc..) *easy for "me" to spot a local vs global variable *helps reduce the bug when accidental global var is created due to misspelling or forgetting to declare a word. And if accidental global is created due to accidental use of ":" vs "::", then it is easier to spot than looking at all the local vars and checking spelling..etc Things that I don't know * performance issues * implementation issues actually, I don't know a whole lot. Just throwing out an idea which "seems" to be very useful in the way I program. I am sure gurujee (indian way of referring to carl S. :) and others on the list can explain why or why not this is possible or useful. rishi