[REBOL] Pointers, Context in Rebol 3.0 (For the real Rebol Lovers)
From: gchillemi:aliceposta:it at: 23-Mar-2007 21:17
Hi to everyone,
time ago I have been in front of a situation unsolvable within Rebol.
Many of you gave me some suggestions compatible with Rebol but they used a
different approach. Now that Rebol 3.0 is under development I want to submit
to the mailing list this message...
Think about an object with some functions inside
template: make object! [
f1: func [a b] [a + b + aaa]
f2: func [a b] [a * b + bbb]
v1: now
v2: []
v3: copy []
aaa: 1
bbb: 2
]
if you execute
inst1: make template []
and then
inst1/f1 3 4
you obtain 8 <- Correct
Lets define a new function
a1: func [a b] [a / b + aaa]
and declare
inst1: make template [f1: :a1]
If you perform
inst1/f1 3 4
aaa is no longer usable and it is reported to have no value. It seems rebol
is not able to bind the new F1 to the context of the parent object.
There could be a way to change this situation in Rebol 3.0 ? I would like to
change the object fuction at object declaration and bid it to the context of
the object which f1 belongs to automatically. A make/deep refinement would
be good to.
Now lets execute the following:
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"
Performing a:
a1: func [a b] [a / b + 1]
should change both INST1/f1 and INST2/f1 because they should point to the
same function as I have declared [F1: :A1]. Instead only a1 is changed
because a1 is copied during object creation and not pointed.
For rebol 3.0 I ask you the ability to point to an external function like
having a pointer to a function in C. Changing the pointed function should
change the working of F1 in both the declared objects.
Lets take both concept in one last line. For Rebol 3.0 I ask the ability
to define many objects
inst1: make template [f1: :a1]
inst2: make template [f1: :a1]
change the pointed function
a1: func [a b] [a * b * bbb]
with the effect of changing f1 in both INST1 and INST2 and having F1 able to
access the object value bbb.
If you introduce the "pointer to function" concept in some way we could
declare (for example) 10.000 object and change the working of their inner
functions with a simple line of code because we have declared them as
pointers and not locally copied.
What you think about this ?
Giuseppe Chillemi