Path: news.daimi.aau.dk!datpete From: datpete-nospam@daimi.aau.dk (Peter Andersen) Newsgroups: comp.lang.beta Subject: Re: copy (clone) of objects with references ? Date: 25 Oct 1995 10:00:14 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 95 Message-ID: <46l1re$hi0@krone.daimi.aau.dk> References: <46g2cq$401@fbi-news.Informatik.Uni-Dortmund.DE> Reply-To: datpete@mjolner.dk (Peter Andersen) NNTP-Posting-Host: fraxinus.daimi.aau.dk Keywords: copy, clone, object, references In <46g2cq$401@fbi-news.Informatik.Uni-Dortmund.DE> Thus spake rosans00@marvin.informatik.uni-dortmund.de (Thomas Rosanski): >I have tried to use the copy (clone) pattern, as described in the Beta FAQ. >But I have problems to get a copy, that has references to identic objects, >which should also be generated new. (if you do not understand me english, >just take a look of me program code:) >(# mat: > (# rows: > (# next: ^rows; > pointer: ^cols; > index: @integer; > #); > cols: > (# next: ^cols; > ele: @integer; > index: @integer; > #); > begin: ^rows; > (* some attributes like init, add, mult, ... *) > copy: (# (* as suggested in the BETA faq *) #); > #); (* end of mat *) > A: @ mat; > B: ^ mat; > do > (* some inits, filling A with references to rows, cols and > setting integer values *) > A.copy -> B[]; (* trying to clone the object A *) >#) >After A.copy -> B[]; B has the same pattern strukture like A, but >the references next[] and pointer[] are NONE. So me question: Is there >an easy way to copy (clone) an object, that contains refernce attributes? >(I think, it is possible via the persistent store - storing A to >a persistent store and restore the content of the persistent store to B - >but this seems to use much time). The FAQ explains it like this: the following trick does the job: P: (# (* internal P structures *) copy:< (* generic copy operation *) (# copyType: ##P; theCopy: ^P; do this(P)## -> copyType##; ©Type[] -> theCopy[]; (* copying internal P structures into theCopy *) <<<<----- INNER copy; (* possible finalization of the copying process *) exit theCopy[] #) #); Q: P(# (* internal Q structures *) copy::< (# Qcopy: ^Q do theCopy[] -> Qcopy[]; (* copying internal Q structures into Qcopy *) <<<<----- INNER copy; (* possible finalization of the Q copying process *) #) #); R: Q(# (* internal R structures *) copy::< (# Rcopy: ^R do theCopy[] -> Rcopy[]; (* copying internal R structures into Rcopy *) <<<<----- INNER copy; (* possible finalization of the R copying process *) #) #); Here the comments (* copying internal R structures into Rcopy *) denotes code not shown, i.e. at this place you should add code that copies *internal* parts of the object, e.g. next[] and pointer[] ind your example. I aggree, that the FAQ example should probably be a little more detailed. Peter Andersen _____________________________________________________________________________ Mjolner Informatics Aps Phone: (+45) 86 20 20 00 ext. 2753 Science Park Aarhus Direct: (+45) 86 20 20 11 - 2753 Gustav Wieds Vej 10 Fax: (+45) 86 20 12 22 DK-8000 Aarhus C, Denmark Email: peter.andersen@mjolner.dk _____________________________________________________________________________ BETA is better -----------------------------------------------------------------------------