Hi, Larry!  I am having fun with your tricks!

I just got into what you were doing.
It's fun to see what /local and saved are doing
after running make-add a couple of times:
>> add6: make-add 6
>> add5: make-add 5

>> source make-add
make-add: func [x /local saved][
  saved: [
    make object! [
      z: 6
      f: func [y][+ z y]
    ]
    make object! [
      z: 5
      f: func [y][+ z y]
    ]
  ]
  get in last append saved make object! [
    z: x
    f: func [y] [+ z y]
    ] 'f
]

I finally figured out that saved is none at the top of the loop,
but that right away it is assigned to the un-named constant (not)
[] that becomes full of objects as make-add is executed.

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?

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?

-galt



Reply via email to