[REBOL] Re: adding set-words to a context from outside
From: rotenca:telvia:it at: 12-Oct-2001 16:22
> sorry for butting in...
> but if you do:
> obj_a: make object! [
> attrib1: 1
> obj_ptr: obj_a
> obj_b: make obj_a [
> attrib2: 2
> Am I right in saying that obj_ptr still references obj_a which only has one
> so is there a way to "grow" an object? cause in some circustances, you
> cannot replace all references to an object (especially when code is dynamic
> and there is no way to know how many references exist).
no, but you can use a method to emulate the growth, here it is:
obj_a: make object! [
obj_b: make obj_a [
obj_a/self: obj_b ;<-
To "transparent" access the grown object, you must always refer the fields of
obj_a with 'self:
The drawback is that obj_a always remains in memory.
Another method is to put all the objects to grown in a block and refers to
them always with the block name:
bl: reduce [ make object! [
obj_a: does [bl/1]
get in obj_a 'attrib1
bl/1: make bl/1 [attrib2: 2 ]
get in obj_a 'attrib2
You can make it with another object:
>> oo: context [o1: context [a: 1]]
>> oo/o1: make oo/o1 [b: 2]
You must never resolve the pointer to o1.