Hi Brett

Good job!  Your "explanation" agrees well with the one I came up with.  Just
one small correction.

You wrote:
> So that "get b" evalutes to b1. "get-it b1" calls the function in the
object
> and thus returns the value of the word "b" in the object that is
associated with "b1".
> This value (a string) is then appended to the value (a block) of the
global word "var".
> 3.3.3) The same goes for the other two iterations, except that for "b3" a
> function of the nested object returns the value of "a" in that context.

Actually the value of the word 'b in the object referenced by 'b1 is the
block [a], which is then appended to the global 'var block.  The same for
'b2.  For 'b3, get-it returns the function func [][a].  So that

>> print mold var
[a a func [][a]]

The 3 instances of the word 'a are each bound to the separate contexts of
'b1, 'b2, and 'b3 respectively. The evaluation of the a's is done by the
print command which reduces the block before forming it, i.e. 'print block
prints the string that would be produce by 'reform block.

>> reduce var
== ["Time" "for you" "to leave!"]
>> reform var
== "Time for you to leave!"

I have included below the script that I used to investigate certain key
points in Carl's Conundrum. It also shows how one can access the same data
in the anonymous object without using the encapsulated get-it func. Of
course, Carl's example was very contrived -- how else could one short script
have 15 uses (one hidden in 'b2) of the word 'b. :-)

BTW The problem with recycle which I posted can be avoided by naming the
anonymous object created by the function 'b.

o: make object! [....

Fun stuff :-)
-Larry

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 27, 2000 8:45 AM
Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(3)


> Well this deserved a response, since it's has consumed so much of my time
:)
> I do not claim my response to be elegant, but I hope it is practically
> accurate.
> And I want to know if I'll be eligible for that master's degree!

> A description of Carl's Completely Confusing Complex Contexts.
>
> b: function [] [b] [
>  make object! [
>   b1: make object! [a: "Time" b: [a]]
>   b2: make b1 [a: "for you"]
>   b3: make b2 [a: "to leave!" b: does [a]]
>   set 'b [b1 b2 b3]
>   get-it: func [b] [get in b 'b]
>  ]
>  b
> ]
....
> var: []
....
> foreach b b: b bind [append var get-it get b] first b
---------------snip rest-----------------------
--------------code-----------------------
REBOL [
 Title: "Carl's conundrum"
 File: %context.r
 Date: 20-Jul-2000
]

b: function [][b] [
 print ["^/function entry: local b type is" type? :b]
 make object! [
  b1: make object! [a: "Time"  b: [a]]
  b2: make b1 [a: "for you"]
  b3: make b2 [a: "to leave!"  b: does [a]]
  set 'b [b1 b2 b3]
  get-it: func [b] [get in b 'b]
 ]
 print ["^/after object: global b type is"
  type? get in system/words 'b
 ]
 print ["^/after object: local b type is" type? :b]
 b
]

print ["^/after function def: global b type is" type? :b]
var: []
foreach b b: b bind [
 print ["^/in foreach: local b is" :b "with value" mold get b]
 append var get-it get b
] first b

print ["^/value of global b is" mold :b]
print ["^/value of global var is" mold var]
print var

print "^/Direct access (not using get-it) to data in object^/"
var2: copy []
foreach x b [append var2 get in get :x 'b]
print mold var2
print var2
;end of script

Reply via email to