[REBOL] Words, Bindings and Contexts. (3)
From: lmecir:geocities at: 23-Jul-2000 23:24
Allow me to present a cleaned Same-context? function. Sorry for
any inconvenience due to reading the former - more complicated
implementation.
; this function can help us explore the Contexts, that aren't
directly available
same-context?: func [
{find out, if the given Words are the Words of the same
Context}
word1 [word!]
word2 [word!]
] [
either global? word1 [
global? word2
] [
same? word1 bind global word1 word2
]
]
Context hierarchy. Pardon?
********************************
Example:
f: func [f-arg] [
prin "F-arg: "
print f-arg
g: func [g-arg] [
prin "G-arg: "
print g-arg
]
g "This is g's argument."
]
f "This is f's argument"
If there were any context hierarchy, then the F's Context should
have been a part of G's Context, which means, that F-arg should
have been in G's Context together with G-arg. Let's see:
word1: probe fourth second :f
word2: probe fourth second get pick second :f 9
same-context? word1 word2
== false
Context hierarchy
? Aye, aye, sir!
****************************************
f: func [x] [
g "this is g's argument."
print x
]
g: func [y] [
x: y
]
word1: second second :g
bind second :g fourth second :f
bind second :g word1
>> f "this is f's argument"
this is g's argument.
Does this prove any "Context Hierarchy?" (the answer left to the
reader)
to be continued...