Subject: Re: Deep copy in lisp: how?
From: Erik Naggum <erik@naggum.no>
Date: 2000/04/09
Newsgroups: comp.lang.lisp
Message-ID: <3164291289641126@naggum.no>

* Courageous <jkraska1@san.rr.com>
| 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