Courageous <jkraska1@san.rr.com> wrote:
+---------------
| > You still have not read the paper by Tim Bradshaw? His queue class is
| > neither a non-standard metaobject nor something that a "default" deep
| > copier can properly duplicate. It is impolite to pursue a thread
| > without investing at least as much time understanding responses as
| > responding.
|
| I completely understand that you can't just deep copy every
| type of object blithely.
+---------------
It's worse than that. The issue has nothing to do with "objects" per se.
Tim's queue "class" can trivially be [and frequently *was*, before CLOS!]
implemented as a single cons cell [sometimes called a "queue header"], and
*none* of the standard copiers for cons cells will "do the right thing" w.r.t.
preserving the required invariant (eq (last (car header)) (cdr header)).
If this isn't clear, observe the following:
> (defun valid-queue-p (header)
(eq (last (car header)) (cdr header)))
VALID-QUEUE-P
> (defvar foo '((a b c d e . #1=(f)) . #1#))
FOO
> foo
((A B C D E F) F)
> (valid-queue-p foo)
T
> (defvar tree-copied-foo (copy-tree foo))
TREE-FOO
> tree-copied-foo
((A B C D E F) F)
> (valid-queue-p tree-copied-foo)
NIL
> (defvar list-copied-foo (copy-list foo))
LIST-FOO
> list-copied-foo
((A B C D E F) F)
> (valid-queue-p list-copied-foo)
NIL
> (defvar seq-copied-foo (copy-seq foo))
SEQ-FOO
> seq-copied-foo
((A B C D E F) F)
> (valid-queue-p seq-copied-foo)
NIL
>
In fact, the *only* way to copy such a queue "correctly" is with an
*application-aware* (or "intention-aware") copy routine, such as:
> (defun copy-queue (header)
(let ((copy (copy-list (car header))))
(cons copy (last copy))))
COPY-QUEUE
> (defvar queue-copied-foo (copy-queue foo))
QUEUE-COPIED-FOO
> (defvar queue-copied-foo (copy-queue foo))
QUEUE-COPIED-FOO
> queue-copied-foo
((A B C D E F) F)
> (valid-queue-p queue-copied-foo)
T
>
-Rob
-----
Rob Warnock, 41L-955 rpw3@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043