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

Cloned object or ???

 [1/6] from: raimunddold::web::de at: 19-Jul-2001 22:53


Hi, I am playing with embedded objects and stumbled about a behaviour I just did not expect. I read through the docs but I could not find anything which clarified the issue for me. Maybe someone can help me. Attached is a short example Thanx, Raimund ----------------------------------------------------- REBOL [ File: %test-embedded-object.r Author: "Raimund Dold" Email: [raimunddold--web--de] ] emb-obj: make object! [ val: 0.0 run: 0 ] my-obj: make object! [ name: "" max: make emb-obj[] ] obj1: make my-obj [ name: "obj1" ] obj2: make my-obj [ name: "obj2" ] obj1/max/val: 2.0 probe obj2 print [equal? obj1 obj2] print [equal? obj1/max obj2/max] -------------------------------------- The output is the following:
>> do %test-embedded-object.r
make object! [ name: "obj2" max: make object! [ val: 2 run: 0 ] ] false true

 [2/6] from: jelinem1:nationwide at: 20-Jul-2001 9:07


Seeing that noone else jumped on this question, I guess I will. The short answer is that you need to use the future enhancement (?) of make/deep to get cloning of imbedded object to behave the way you expect (ie with distinct embedded objects). When you code: my-obj: make object! [ name: "" max: make emb-obj[] ] ...you are evaluating the block once, creating my-obj and also creating the emb-obj object. When given as an argument to 'make, my-obj gets copied (not to be confused with the action 'copy) but this copy does not replicate imbedded objects. If you are familiar with pointers: the pointer to emb-obj, which is the value of 'max, gets copied. Both parent objects are then pointing to the same child object. A work-around is to write a function around the 'make which will effectively perform the replication of the imbedded objects. - Michael Jelinek From: Raimund Dold <[raimunddold--web--de]>@rebol.com on 07/19/2001 03:53 PM Please respond to [rebol-list--rebol--com] Sent by: [rebol-bounce--rebol--com] To: "Rebol" <[rebol-list--rebol--com]> cc: Subject: [REBOL] Cloned object or ??? Hi, I am playing with embedded objects and stumbled about a behaviour I just did not expect. I read through the docs but I could not find anything which clarified the issue for me. Maybe someone can help me. Attached is a short example Thanx, Raimund ----------------------------------------------------- REBOL [ File: %test-embedded-object.r Author: "Raimund Dold" Email: [raimunddold--web--de] ] emb-obj: make object! [ val: 0.0 run: 0 ] my-obj: make object! [ name: "" max: make emb-obj[] ] obj1: make my-obj [ name: "obj1" ] obj2: make my-obj [ name: "obj2" ] obj1/max/val: 2.0 probe obj2 print [equal? obj1 obj2] print [equal? obj1/max obj2/max] -------------------------------------- The output is the following:
>> do %test-embedded-object.r
make object! [ name: "obj2" max: make object! [ val: 2 run: 0 ] ] false true

 [3/6] from: raimunddold:web at: 22-Jul-2001 9:59


Thanx for the reply, hmm, so I have to do it like the following to get the behaviour I expected? Not very handy Raimund REBOL [] emb-obj: make object! [ val: 0.0 run: 0 ] make-my-obj: func [][ make object! [ name: "" max: make emb-obj[] ] ] obj1: make-my-obj obj2: make-my-obj On Friday 20 July 2001 16:07, you wrote:

 [4/6] from: rotenca:telvia:it at: 22-Jul-2001 13:09


-----Messaggio Originale----- Da: "Raimund Dold" <[raimunddold--web--de]> A: <[rebol-list--rebol--com]> Data invio: 22 lug 2001 09:59 Oggetto: [REBOL] Re: Cloned object or ???
> Thanx for the reply, > > hmm, so I have to do it like the following to get the behaviour I expected? > Not very handy
Try: make-my-obj: func [][ make object! compose [ name: "" max: (make emb-obj []) ] ] ciao romano

 [5/6] from: joel:neely:fedex at: 24-Jul-2001 9:31


Hi, Raimund, Sorry for the delayed reply (I've been on vacation). Raimund Dold wrote:
> I am playing with embedded objects and stumbled about a > behaviour I just did not expect. I read through the docs > but I could not find anything which clarified the issue > for me. Maybe someone can help me. >
You might find this old post from the mailing list of interest.
> [REBOL] Re: More on "embedded" objects (an enhancement) > From: Joel Neely (view other messages by this author)
<<quoted lines omitted: 170>>
> virtual cookie for your patience and endurance!) > -jn-
-- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com

 [6/6] from: joel:neely:fedex at: 25-Jul-2001 9:08


Hi, Raimund, Sorry for the delayed reply (I've been on vacation). Raimund Dold wrote:
> I am playing with embedded objects and stumbled about a > behaviour I just did not expect. I read through the docs > but I could not find anything which clarified the issue > for me. Maybe someone can help me. >
You might find this old post from the mailing list of interest.
> [REBOL] Re: More on "embedded" objects (an enhancement) > From: Joel Neely (view other messages by this author)
<<quoted lines omitted: 170>>
> virtual cookie for your patience and endurance!) > -jn-
-- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com

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