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

[REBOL] Re: adding set-words to a context from outside

From: rotenca:telvia:it at: 12-Oct-2001 16:22

Hi, Max
> 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 > element? > > 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! [ attrib1: 1 ] obj_ptr: obj_a obj_b: make obj_a [ attrib2: 2 ] obj_a/self: obj_b ;<- To "transparent" access the grown object, you must always refer the fields of obj_a with 'self: probe obj_a/self/attrib1 probe obj_a/self/attrib2 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! [ attrib1: 1 ] ] 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/a
== 1
>> oo/o1: make oo/o1 [b: 2] >> oo/o1/a
== 1
>> oo/o1/b
== 2 You must never resolve the pointer to o1.
> -Max
--- Ciao Romano