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 17:34

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. Return 1, for example, make the context block returns an integer, but the make object! returns always the self value. So you can something like:
>> type? make object! [self: "string" a: 1]
== string!
>> type? make object! [set 'o self self: "string" a: 1]
== string!
>> probe o
make object! [ a: 1 ]
>From the last example it seems to me that 'self is set to the object! before
any execution, and changed at the end (for your sim-object!). It seems it is never unset! So blank-object could be more simple: blank-object: func [ {make a blank object} blk [block!] ] [ context compose [exit (blk)] ] You can do also more complex things:
>> type? f: make object! [self: does [print "I am a function" print ["a =" a]]
a: 1] == function! ; the body of which is bound to an hidden context
>> a: 2
== 2
>> f
I am a function a = 1 and so on. 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 :-).
> My goal was to find out, whether the examined word is unbound or not. I am > pretty sure, that the word in question is unbound only if the error id is > 'not-defined. In the above case the source of the error isn't the GET/ANY > expression, but the ANY-TYPE? function, which has nothing to do with the > binding of the examined word. (the examined word is clearly bound to the > created object)
I think you are right.
> Nevertheless, it is a shocking experience, that there is a Rebol value which > isn't acceptable for the ANY-TYPE? function.
Perhaps we have found the only true unset word in Rebol, the others have always a value: unset!.
>> o: make object! [break a: 1] >> get in o 'a
we do not need get/any !! But:
>> type? get in o 'a
** Script Error: type? expected value argument of type: any-type ** Near: type? get in o 'a the value of a is not of any-type!, neither unset!, it has no no value (nothing! datatype :-). But, there is always a but:
>> type? o/a
== unset!
>> get o/a
** Script Error: get expected word argument of type: any-word ** Near: get o/a
> I suggest you to summarize your > findings and send them all to feedback.
Sent, but Feddback do not sent back any feedback :-), neither the ticket number, i have the sensation to send my message to the land of no return. Ciao Romano