Hello [EMAIL PROTECTED]!

On 03-Lug-00, you wrote:

 C> But now the context thing comes in for real, ;-)

Yup. :-)

 C>>> a: 0 f: func [] [a]

The 'A in the body block of the function F is bound to the global
context.

 C>>> o1: make object! [a: 1 g: func [] [a]] o1/g

G is a new function; the 'A in his body block is bound to the
object's context.

 C>>> o2: make object! append [a: 2 g:] [:f] o2/g

G just refers to F.

 C>>> o3: make object! append [a: 3 g:] compose/deep [first [(:f)]] o3/g
 C>>> o4: make object! append [a: 4 g:] reduce ['first reduce [:f]] o4/g

These are totally equivalent; G refers to F here too.

 C>>> o5: make object! append [a: 5 g:] reduce ['func first :f second :f] o5/g

Here a new function is created, but it shares its body block with
F's. Thus, when BIND changes it to bind its words to the object's
context, F is changed too.

 C>>> o1/g o2/g o3/g o4/g o5/g a
 C> 1
 C> 5
 C> 5
 C> 5
 C> 5
 C> 0

The 'A in F's body block is now bound to O5's context, so you get
5 each time you call F (or the function sharing its body block
with it).

 C> contexts, but - as Ladislav pointed out - doesn't work for
 C> native!s and action!s.
 C> Any idea on how an o6 can be done, which preserves context
 C> *and* works for native!s and action!s?

You can't change the binding of a native function anyway (and you
don't have any reason to), so...

 C> And finally, why do I get that strange 1 5 5 5 5 0 results?

See above.

Regards,
    Gabriele.
-- 
Gabriele Santilli <[EMAIL PROTECTED]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

Reply via email to