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

[REBOL] Re: R: Re: Pointers, Context in Rebol 3.0 (For the real Rebol Lovers)

From: gabriele::colellachiara::com at: 28-Mar-2007 0:16

2007/3/27, Giuseppe Chillemi <gchillemi-aliceposta.it>:
> Where I could find some documentation on object to understand the results I > get using the following commands:
I think this should be in the Core guide somewhere... but anyway:
> probe first :obj > > [self a]
You can model a context as a pair of blocks. The first block can only contain word! values; the second block contains the values that are associated with the words in the first block. So if the first block is [a b c] and the second block is [1 2 3], a is associated with 1, b with 2 and c with 3. FIRST on an object returns the first block. So it's basically the list of words in the context. keep in mind that the words in this block are not bound.
> probe second :obj > > > [make object! [ > > a: 1 > > ] 1]
SECOND returns the second block, so the block of values. Here you can see the values of SELF and A. SELF obviously refers to the object itself.
> probe third :obj > > > [a: 1]
THIRD was added more recently. It returns a block that can be used with CONSTRUCT to recreate the object. So, SELF is omitted (because it is created automatically for object, and for obvious reasons), and you just get [a: 1].
> > They are *not* copied, they are the same function value. (And this > > is actually a problem, because it can't be bound to different > > contexts!) But changing the word does not change the value. > > I do not understand why it is actually a problem, could you explain ?
Since the function is not copied, the body block is the same for all the objects. So are the words contained in it. But a word can only be bound to one context at a time. So you cannot have the function bound to more than one of your objects. If you bind it to INST1 you lose the binding to INST2 and viceversa. If you want to share the function across contexts, you need to pass it the instance as argument expliticly, otherwise you need a copy of the function for each object. Indeed, in REBOL methods (which are called actions - see the action! type) are usually not put in the object at all, and the object is just the first argument of the function. Regards, Gabriele.