Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] R: Re: Pointers, Context in Rebol 3.0 (For the real Rebol Lovers)

From: gchillemi:aliceposta:it at: 27-Mar-2007 20:55

> You can change the body code of the function > > > a1: func [a b] [a / b] > > > > inst1: make template [f1: :a1] > > inst2: make template [f1: :a1] > > > > I expect that both inst1 and inst2 share the same "pointer to a1" > > a1 and f1 in each instance refer to the same function, yes.
In other words if I write a1: func [a b] [a + b * a] I force a1 to point to something else while inst1/f1 point to the old function a1 pointed to. Previously I thought that f1: :a1 was meaning "use a1 as pointer to the function and f1 will point to whather a1 is pointing". Changing the pointer should change the function pointed to. Now it is clear that inst1/f1 point to the content of a1 ant not to the content which the pointer a1 is pointing too (subtle difference)
> You could do this: > > inst1: make template [] set in inst1 'f1 :a1 > inst2: make template [] set in inst2 'f1 :a1
Nice, but this does not solve the problem of using values contained inside the object. As Gabriele Santilli noted in its message I must add bind second :a1 inst1 bind second :a1 inst2 to let a1 content see the values inside the objects
> Another way is to put functions in a sub-object, > just like face/feel. eg: > > template: context [ > aaa: 1 > funcs: context [f1: none f2: none] > ] > > a1: func [a b] [a / b + 1] > template/funcs/f1: :a1 > > inst1: make template [] > inst2: make template [] > > inst1/funcs/f1 3 4 > inst2/funcs/f1 3 4 > > These are a little bit uncomfortable.
I'll further investigate on this solution, I still do not understand the difference. Could you explain ? Giuseppe Chillemi