Hi, Joel,

although not been asked, trying to answer some questions.

1) The model of binding Gabriele (not Gabrielle) proposed was proposed as a
hypothesis, that could explain the Rebol behaviour. Since then it has
succeeded to explain every situation encountered and to make valid
predictions, so it's validity is much less questionable than validity of any
other binding model proposed.

2) When you use a code like:

a: 1
b: 'a
use [a] [print 'a = b print same? 'a b]

you get:

true
false

which really means that the words you are comparing are somehow equal and
somehow different.

The model:

Every word (e.g. 'a) is an entity that has at least attributes:

text-representation (e.g. "a")
binding (e.g. the global context)

>From the model point of view the words are considered equal as long as their
text-representations are equal. The words compared above are considered
equal, but are not the same, because their binding attributes differ.

3) About the difference between the global context and any other context:

Any word can be bound to the global context. (In other words: the global
context is enlarge-able.) That is why the 'c being bound to the global
context looks "clobbered".

As to the local contexts:

The local contexts created with a help of the Use function (or a similar
mechanism) are limited in the following sense: Bind Word Local-Context-Word
doesn't change the Word's binding, if it doesn't encounter the Word's
equivalent in the Local-Context. That is why within F 'a and 'b don't change
their binding - the 'a and 'b words are not in the F's local context.

Ladislav

----- Původní zpráva -----
Od: <[EMAIL PROTECTED]>
Komu: <[EMAIL PROTECTED]>
Odesláno: 27. prosince 1999 20:15
Předmět: [REBOL] Series essay Re:(4)


> Gabrielle,
>
> Thanks for your descriptions!  They've stimulated some additional
> questions, given below.  Might I trouble you for some more ideas?
>
> [EMAIL PROTECTED] wrote:
> >
> > My model for binding/contexts is the following:
> >
> >     {{context! * *}}
> >      ^         | `---------> <<... 1 ...>> ; values (simplified
notation)
> >       \        |
> >        \       `-----------> <<... a ...>> ; words (simplified notation)
> >         \
> >          \
> > {{word! * *}}
> >         |
> >         V
> >         << #"a" >>
> >
>   ...
> >
> > >> obj: make object! [
> > [    a: 1
> > [    b: 2
> > [    ]
> > >> first obj
> > == [self a b]
> > >> second obj
> > == [
> >     make object! [
> >         a: 1
> >         b: 2
> >     ] 1 2]
> >
>
> >From other languages, I had a concept of "environment" -- basically
> a dictionary ("a-list" in LISP, "hash" in Perl, etc.) which supported
> looking up a variable/word/token and obtaining the corresponding
> value.  That much seems compatible with the model you provided.
>
> You've persuaded me that one part of that concept does NOT apply to
> REBOL -- that of searching a chain of environments, from most-local
> to most-global, to find the appropriate binding for a word.  While
> that notion works well for pure lexical scoping and pure dynamic
> scoping, I don't see how it effectively supports REBOL's
> word-at-a-time capability accessed via 'bind.
>
> It seems clear that context-juggling is implicitly performed via
> entry and exit to the bodies of functions and 'use, as in:
>
>     >> a: "global a"
>     == "global a"
>     >> f: func [][print a]
>     >> g: func [/local a][a: "g's local a"  print a  f  print a]
>     >> h: func [][use [a][a: "h's local a" print a g print a]]
>     >> h
>     h's local a
>     g's local a
>     global a
>     g's local a
>     h's local a
>     >>
>
> I'm not clear on whether it's better to think of the above as
>
> 1)  a single word 'a whose context is being magically managed by
>     the interpreter, or
>
> 2)  three words, whose names happen to share the same spelling.
>
> To display my ignorance (and confusion) on this point, consider this
> console transcript:
>
>     >> a: 1
>     == 1
>     >> b: 2
>     == 2
>     >> e: [a b c]
>     == [a b c]
>     >> reduce e
>     ** Script Error: c has no value.
>     ** Where: c
>
> That was expected, as I had not defined 'c previously.
>
>     >> f: func [n /local c] [c: n  bind e 'c  print e]
>     >> f 12
>     1 2 12
>
> So far, still expected, as 'f supplies a context for 'c to be
> evaluated in.
>
>     >> e
>     == [a b c]
>     >> print e
>     1 2 12
>     >> c
>     ** Script Error: c has no value.
>     ** Where: c
>     >> same? 'c third e
>     == false
>
> This WASN'T what I expected.  It appears that the third element of
> 'e is a different 'c from the one whose name I can type into
> the console.
>
>     >> g: func [m /local a b] [bind e 'a  a: m  b: m + 1  print e]
>     >> g 20
>     20 21 12
>     >> e
>     == [a b c]
>     >> print e
>     20 21 12
>
> No surprise here.
>
>     >> h: func [][bind e third e  print e]
>     >> h
>     20 21 12
>
> Hmmmm.  Within 'f (where we've bound 'c) the words 'a and 'b would
> have evaluated globally.  However, attempting to bind 'e back to
> that context doesn't restore 'a and 'b (in e!) to refer to the
> global 'a and 'b.
>
>     >> bind e 'f
>     == [a b c]
>     >> print e
>     ** Script Error: c has no value.
>     ** Where: c
>     >> a
>     == 1
>     >> print first e
>     a
>     >> print get first e
>     1
>     >>
>
> But 'f is defined in the global context for which 'a -> 1, 'b -> 2,
> and 'c is undefined.  So, although it seems clear why this last use
> of 'bind restored 'a and 'b (in 'e!) to their global binding, it's
> not immediately obvious to me why 'c (in 'e) got clobbered (when
> the 'bind in 'g didn't affect it).
>
> Any suggestions?
>
> >
> > So, every word simply mantains a reference to a context (and
> > probably, for efficiency, directly to its value in that context
> > --- this could be proven in the previous version of REBOL),
>
> Fascinating!  Could you provide a code speciment that demonstrates?
>
> > and
> > all the functions that modify the binding of a word simply change
> > that reference.
> >
> > This has allowed me to explain almost every case I encountered in
> > REBOL so far; I hope it can be useful. I don't know how much
> > accurate it is.
> >
>
> I'm still puzzled about what appears to be evidence of TWO words
> named 'c above.  I'd be very interested in your thoughts on that.
>
> -jn-
>
>

Reply via email to