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

2001-10-12 Thread Ingo Hohmann

Hi Anton,

try 

Once upon a time Anton Rolls spoketh thus:
 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

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


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with unsubscribe in the 
subject, without the quotes.




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

2001-10-12 Thread Media

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
--

- Original Message -
From: Ingo Hohmann [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, October 12, 2001 5:06 AM
Subject: [REBOL] Re: adding set-words to a context from outside


 Hi Anton,

 try

 Once upon a time Anton Rolls spoketh thus:
  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

 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


 --
 To unsubscribe from this list, please send an email to
 [EMAIL PROTECTED] with unsubscribe in the
 subject, without the quotes.


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with unsubscribe in the 
subject, without the quotes.




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

2001-10-12 Thread Romano Paolo Tenca

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



-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with unsubscribe in the 
subject, without the quotes.