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

[REBOL] Re: local vars in functions

From: lmecir:mbox:vol:cz at: 1-May-2002 21:34

Hi Romano, thank you, <Romano> Hi Ladislav, c> unset in blk: context compose [exit (blk)] 'self
> blk > ] > </Romano> > > :-o I would have guessed, that the only way how to do that would be: > > blank-object: func [ > {make a blank object} > blk [block!] > ] [ > unset in blk: context compose [return self (blk)] 'self > blk > ] > > It is a mistery for me, why exit works in this case.
I do not think, i learned it from you :-) An object always return the self value whatever the code executed will return. Every return value is replaced by the value of 'self. </Romano> This looks *very* strange to me. (I wonder, what would Joel say to that?) <Romano> ... 'self is set to the object! before any execution, ... </Romano> Exactly that I wanted to underline. That is why I designed the sim-make-object! to set the word before the execution too. The blank object is simply a blank context, no mistery in it. <Romano> You can also use throw or break to stop the block execution:
>> probe make object! [break a: 1]
make object! [ a: end ]
>> probe make object! [throw "" a: 1]
make object! [ a: end ] So to emulate it you must catch return, exit, break and throw. The only exception is make error!, in this case, the object creation is stopped, the object is not created and the error returned, not the self value (of an unexisting object :-). </Romano> Now I see. I didn't expect any special properties of the kind you are describing, to be honest. I would suggest a more consistent behaviour WRT RETURN, EXIT, BREAK and THROW. (What would Joel say, again?). There is just one problem, then: the code will be less readable than it is! Nevertheless, I should replace the code as you suggested. Anyway (readability reasons) I will preserve the structure, where the MAKE function first creates a (totally) blank object and then sets the 'self word explicitly (to underline the fact, that 'self is really being set before the execution) etc...