From ... From: Erik Naggum Subject: Re: Deep copy in lisp: how? Date: 2000/04/09 Message-ID: <3164291289641126@naggum.no>#1/1 X-Deja-AN: 608772642 References: <38F0B90A.8FC4B502@san.rr.com> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 955302573 25937 195.0.192.66 (9 Apr 2000 17:49:33 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.5 Mime-Version: 1.0 NNTP-Posting-Date: 9 Apr 2000 17:49:33 GMT Newsgroups: comp.lang.lisp * Courageous | I have a CLOS object which may contain an arbitrary graph of other | objects. This graph may be cyclic. I'm looking for an easy way to deep | copy the object. the only easy way out is to write a copier that knows what it's doing. any easier way out would violate "as simple as possible, but no simpler". | I've been told that generic deep copy might be implementing by writing | the object to a stream, and then reading back from that stream. you've been told that? what a joker that must have been! how do you think you would proceed to implement readers and writers for the objects? do you think _they_ come in generic versions that do everything right? (for the languages where you may use a generic version that does it wrong most of the time, which you usuallyq observe if you try, there _is_ the merit to this language design that most "modern programmers" (= dummies) are a lot happier when they something out and see it fail, then do it "right" (= less _obviously_ wrong), than to know it would fail and know they had to do it right from the start.) implementing a mechanism that avoids descending into cyclic structures is amazingly easy. detection is easy with the rabbit and the hare algorithm. a hash table of copied objects avoids all possible problems to begin with. #:Erik