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

[REBOL] Re: local vars in functions

From: tim:johnsons-web at: 23-Apr-2002 19:55

* Rishi Oswal <[rishioswal--yahoo--com]> [020423 19:18]:
> One part of REBOL that can feel odd is when i have to > define local variables of a function in the first > block of the function. I find it a bit annoying to > have to add new variables to the list for every little > local variable I use. In addition, I feel it clutters > up the first block and increases function size. In > addition, the way it is currently done could make it > easy to create hard to detect bugs.
Yeah. I've been wondering why rebol does that.... Could it be better to make any 'word local by default, and make that word global optionally with a key word and maybe another keyword to 'protect it? I'm sure there is a good reason for the current approach, but I don't know what it is. -tim-
> What I would like to see is another shortcut to > creating local variables in any context (function, > innerfunction, loop). The obvious way I see of doing > this is as follows: > > myfunc: func [][ > localvar:: $25 > myinnerfunc: func [][ > innerlocal:: $10 > print localvar ; prints $25 > ] > print innerlocal; error! > ] > print localvar ; error! > > using the "::" for local var will make it more > convienient to create local vars (which i use all the > time over global vars). In addition, it will help > prevent some errors of accidental global var creation > because it is now easy to spot a local var. Best of > all, this type of shortcut would not break anything in > rebol. You could even use this in a loop: > > for count 1 10 1 [ > localvar:: "hello" > ] > > Using the "::" shortcut in a global context would be > the same as using a ":". > > The disadvantage I see is that it adds another thing > to the language.. But consider that now we could stop > using the /local keyword, reduce bugs, and use it > consistently everywhere, overall it can simplify > things. > > Anybody have other reasons as to why it was not done > this way?? > > Perhaps there is a performance issue?? > > rishi > > __________________________________________________ > Do You Yahoo!? > Yahoo! Games - play chess, backgammon, pool and more > http://games.yahoo.com/ > -- > To unsubscribe from this list, please send an email to > [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com