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

[REBOL] local vars in functions

From: rishioswal::yahoo at: 23-Apr-2002 20:08

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. 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