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

[REBOL] Re: Cloned object or ???

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