Hello [EMAIL PROTECTED]!

On 27-Dic-99, you wrote:

 j> Thanks for your descriptions! They've stimulated some
 j> additional questions, given below. Might I trouble you for
 j> some more ideas?

No trouble. :-) I'll try to provide you my own answers, even if
they could be wrong. :-)

 j> You've persuaded me that one part of that concept does NOT
 j> apply to REBOL -- that of searching a chain of environments,
 j> from most-local to most-global, to find the appropriate
 j> binding for a word.

Yes. Indeed, in the beginning I thought that a word had to mantain
a list of contexts, from the most "local" to the most "global",
but Ladislav (IIRC) showed me I was wrong. The magic is done by
bind, which sets the reference to the context in a word only if it
is present in that context.

 j> It seems clear that context-juggling is implicitly performed
 j> via entry and exit to the bodies of functions and 'use, as in:

Actually, nothing happens when entering or exiting the functions.
The binding is done when they are created. That is, make function!
creates a new context based on the spec, and then binds the body
block to that context.

 j> 2) three words, whose names happen to share the same spelling.

Three different words. It's like having series with the same
sequence but a different position --- you have words with the same
spelling but different contexts.

 j>>> same? 'c third e
 j>    == false

 j> This WASN'T what I expected. It appears that the third element
 j> of 'e is a different 'c from the one whose name I can type
 j> into the console.

Not really surprising:

           {{context! * *}} ; the global context
           ^          | `----->  << ... >>
           |          `------->  << ... >>
           |
 {{word! * *}} ; global 'c
         |
         `---> << #"c" >>
               ^
               |
           .---'
          /
 {{word! * *}} ; local 'c
           |
           |
           v
           {{context! * *}} ; the local context
                      | `----> << 12 >>
                      `------> << c >>

Even if they referred to the same sequence of character, they
would refer to a different contexts. Actually, in your example
even the sequence of characters would have not been exactly 
the same.

 j> Hmmmm. Within 'f (where we've bound 'c) the words 'a and 'b
 j> would have evaluated globally. However, attempting to bind 'e
 j> back to that context doesn't restore 'a and 'b (in e!) to
 j> refer to the global 'a and 'b.

This is not a surprise too. Within f's context there's no 'a or
'b, so bind simply ignores them. Their binding is not changed;
keep in mind that you are not binding code, but single words ---
every word can have its own context. The following example should 
not surprise you:

>> block: [x]
== [x]
>> x: 1
== 1
>> reduce block
== [1]
>> use [x] [x: 2 insert tail block 'x]
== []
>> use [x] [x: 3 insert tail block 'x]
== []
>> use [x] [x: 4 insert tail block 'x]
== []
>> block
== [x x x x]
>> reduce block
== [1 2 3 4]

See, four different x's.

 j> But 'f is defined in the global context for which 'a -> 1, 'b
 j> -> 2, and 'c is undefined. So, although it seems clear why
 j> this last use of 'bind restored 'a and 'b (in 'e!) to their
 j> global binding, it's not immediately obvious to me why 'c (in
 j> 'e) got clobbered (when the 'bind in 'g didn't affect it).

Because 'c actually exists in the global context, and its value is
unset!. Look:

>> c
** Script Error: c has no value.
** Where: c
>> type? get/any 'c
== unset!

 j>> So, every word simply mantains a reference to a context (and
 j>> probably, for efficiency, directly to its value in that
 j>> context --- this could be proven in the previous version of
 j>> REBOL),
 j> Fascinating! Could you provide a code speciment that
 j> demonstrates?

REBOL <= 2.1 made possible to modify the first and the second
componets of objects, that is, the list of words and the list of
values of its context. Something like:

>> obj: make object! [a: 1 b: 2]
>> words: first obj
== [self a b]
>> values: second obj
== [
    make object! [
        a: 1
        b: 2
    ] 1 2]
>> change next words 'c
== [b]
>> words
== [self c b]
>> print mold obj

make object! [
    c: 1
    b: 2
]

(This is no longer possible, for security; now first obj would
return a copy of the actual block.)
If we had an 'a bound to that context that evaluated to 1 before
the change, it would continue to evaluate to 1 after the change,
even if 'a no more exists in that context after the change.

Regards,
    Gabriele.
-- 
o--------------------) .-^-. (----------------------------------o
| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila |
| GIESSE on IRC     \ \-\_/-/ /  http://www.amyresource.it/AGI/ |
o--------------------) `-v-' (----------------------------------o

Reply via email to