Hi Galt
You wrote:
> I have a question:
> Is the function f inside each object in saved actually pointing
> to the same code, or is it a separate instance completely?
AFAIK the functions in each of the stored objects are all independently
created. They look identical when using 'source because 'source does not
indicate the context. One of the real shockers in REBOL is that contexts
allow things to look identical which are not because of the context. A nice
example due to Gabriele IIRC:
data: []
use [x][x: 5 append data 'x]
use [x][x: 6 append data 'x]
use [x][x: 7 append data 'x]
>> data
== [x x x]
>> reduce data
== [5 6 7]
> I see now of course that z sure looks like a free variable,
> resolving to the context of the object? Does an object have a context,
too?
> Does the object reach into the context of f and tweak it's value, or does
> it run f inside it's own object context?
I think that what we are doing in returning 'f is making an entity in the
context local to 'make-add available externally. So we are able to directly
reference the function inside the unnamed object inside the local block
'saved inside the function 'make-add. And the value of 'z is also known in
the context of the unnamed object.
It should also be possible to modify the contents of the 'saved block (for
instance delete some of the objects) and still have the other functions
work. Cautions on GC and internal stack overflow errors.
BTW When I was first learning REBOL last fall I tried programming many of
the samples from the "Wizard Book" by Sussman et. al.. I found that it was
not really possible to write programs with the same behavior as the Scheme
examples, possibly because of the lack of dynamic binding in REBOL.
Presumably in REBOL 1.x this was possible.
One way of looking at the encapsulated 'make-add is that while REBOL does
not natively provide them, it can be used to create (somewhat cumbersome)
structures which emulate certain features of languages like Scheme.
Cheers
-Larry