Hi Elan,

You wrote:
>Example 1 for Context Hierarchy:
>
>global-word: "This is the global word."
>
>f: func [f-arg] [
>  g: func [g-arg] [
>    print [g-arg f-arg global-word]
>  ]
>  g "This is g's argument."
>]
>
>In this example we are dealing with three contexts: the global context, in
>which global-word is defined, the function f's local context in which f-arg
>is defined, and finally, the function g, in whose local context its g-arg
>is defined.
>
>The g function inherits f's context table in which f-arg is defined.
>Therefore g has access to all three words: It can access global-word,
>because global-word is defined in the global context, and g has access to
>the global context. It can access g-arg, because g-arg is defined in its
>own private context table. The g function also has access to f-arg, which
>is defined in f's local context. The g function accesses f-arg in f's
>context table, which g inherits.

I think it's needlessly complex to say that the g function "has access
to f-arg". It's much simpler to say that the word 'f-arg is bound to the
context of the function F, and that the function G has no privileged access
to that binding of 'f-arg by being within some kind of hierarchy.
(The binding of 'f-arg of course took place even before the function G
was created.)

Here's proof, I think:

>> f: func[x y][x + y]
>> g: func[x y][x + y]
>> f 1 2
== 3
>> g 5 6
== 11
>> b: copy second :f
== [x + y]
>> c: copy second :g
== [x + y]
>> append clear second :f c
== [x + y]
>> append clear second :g b
== [x + y]
>> f 1 2
== 11
>> g 5 6
== 3
>> f 10 11
== 11
>> g 5 6
== 21


Here I've rebuilt the code for F and G, and now their bodies contain words
'x and 'y bound within each other's contexts. I think it's simplest to say
that those words "know" where they are bound. When you call F, it sets
the values of all instances of 'x and 'y bound to its context, but in this
case all those instances are now in the body of G, not within F's own
body. F doesn't see the word 'x within its body, and look up the value of
'x in some table, it just uses the value that results when 'x is evaluated.

See you,
Eric

Reply via email to