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

adding set-words to a context from outside

 [1/5] from: arolls::idatam::com::au at: 12-Oct-2001 18:15


Does anyone know how to add words to an object from outside that object? For example, take an empty object o: o: context [] ; Now some voodoo stuff happens ; here that adds a word to o ; and the result... probe o make object! [ a: none ] And if you want to know why I want to do this... I am at work and cannot remember. :) Anton.

 [2/5] from: ingo:2b1 at: 12-Oct-2001 11:06


Hi Anton, try Once upon a time Anton Rolls spoketh thus:
> Does anyone know how to add > words to an object from outside
<<quoted lines omitted: 3>>
> ; Now some voodoo stuff happens > ; here that adds a word to o
o: make o [a: none]
> ; and the result... > > probe o > > make object! [ > a: none > ]
But remember, that 'make doesn't create deep copies, so you might run into some surprises, if you tried to assign this to another word. But setting it back to the same is safe. kind regards, Ingo

 [3/5] from: media:quazart at: 12-Oct-2001 8:27


Hi, 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). -Max ---------------------------------- Maxim Olivier-Adlhoch

 [4/5] from: rotenca:telvia:it at: 12-Oct-2001 16:22


Hi, Max
> sorry for butting in... > but if you do:
<<quoted lines omitted: 10>>
> 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

 [5/5] from: ingo:2b1 at: 12-Oct-2001 17:03


Hi Maxim, you are right, obj_ptr will stay pointing at the initial obj_a, as far as I know, there is no possibility to grow an object (yet?).
>> obj_a: make object! [
[ attrib1: 1 [ ]
>> obj_ptr: obj_a >> obj_a: make obj_a [
[ attrib2: 2 [ ]
>> probe obj_ptr
make object! [ attrib1: 1 ]
>> probe obj_a
make object! [ attrib1: 1 attrib2: 2 ] Ingo

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted