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

[REBOL] Re: Binding a changed function within a context

From: g:santilli:tiscalinet:it at: 5-Oct-2002 20:02

Hi Laurent, On Saturday, October 5, 2002, 6:51:14 PM, you wrote: LG> reading your second example I came to the conclusion that 'bind must actually do LG> the binding then return the exact words it was passed as parameters. It changes the argument block (unless the /COPY refinement is used) and returns it. LG> First of all, in that test the word "self" is used in a context where it seems LG> to be innapropriate (there is no object lying around) : what does 'self refer to LG> in such a case ? First of all, notice it is a lit-word, and not a word. I.e. if you write:
>> 'self
== self you don't get an error, because you are not trying to get a value from the word "self", but rather you are referring to the word itself (thus "literal word"). After that, notice also that I wrote "in my-context 'self".
>> help in
USAGE: IN object word DESCRIPTION: Returns the word in the object's context. IN is a native value. ARGUMENTS: object -- (Type: object) word -- (Type: word) So "in my-context 'self" takes the word "self" and returns it bound to the object's context. I used "self" just because any object has that word. I could have used any other word in the object. (If the passed word is not present in the object, IN returns NONE.) So we have: (bind [...] (in my-context 'self)) BIND takes a word as its second argument, and binds the block passed as its first argument to the same context to which that word is bound. Since IN returns the word 'SELF bound to the context of the object MY-CONTEXT, basically we are binding the block to the context of the object MY-CONTEXT. For better readability, one could write: bind-to-object: func [block object] [bind block in object 'self] and use that instead. LG> Since context has much importance in rebol, I guess it's good to know such thing LG> ;) Absolutely. Feel free to ask. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r