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

[REBOL] Re: local vars in functions

From: rotenca:telvia:it at: 1-May-2002 0:03

Hi, Anton, I agree with Ladislav (BTW he created, i think, a "perfect" simulation of make object! in one of his articles). As you can see here:
>> a: 1
== 1
>> context [
print unset? a ;(1) a: "b" ;(2) ] true the word 'a in the print statement in the block context (1) is unset: it must be local, because the global 'a is = 1. Being unset, it is not already initialized with "b", and the expression (2) has not been executed, but the interpreter already "knows" that the word 'a is local to the block context. Conclusion: before executing the block context, all the set-words are found in the upper level block, a new context build, all its values set to unset! and the block bound to the new context. Only at this time the block is executed. This could be delayed easy, like in a function, without changing the context work. Another example will prove that an object can be created without executing all its block. Indeed is a "monster" object for a bug in Rebol (someone has reported it to feedback?):
>> x: does [context [return 1 a: 2 b: 3]] >> print type? o: x
object
>> print type? o/a
unset
>> print type? o/b
unset I call It a "monster" because this object fails in many manners: if this is standard:
>> first o
== [self a b] this is not standard:
>> probe o
make object! [ a: end ;?????? b: unset ] neither this:
>> second o
== [ make object! [ a: end b: unset ]] and this:
>> third o
== [a:] --- Ciao Romano