Hi!
The keywords and summary pretty much say it all.
Suppose I have a structure foo whose fields themselves have been
assigned objects of type bar where bar is another structure.
Will the function copy-foo recursively copy the objects of type bar as
well, or will it just assign pointers?
If the later is true, is there someway of specifying to copy-foo that
it should copy recursively?
Thanks,
--Raman
--
T. V. Raman <·····@cs.cornell.edu>Tel: (607)255-7421 R 272-2435
Office: 5162 Upson Hall,
Department of Computer Science, Cornell University Ithaca NY 14853-6201
Res: 226 Bryant Avenue Ithaca NY 14850
In article <····················@cs.cornell.edu> ·····@cs.cornell.edu (T. V. Raman) writes:
>Will the function copy-foo recursively copy the objects of type bar as
>well, or will it just assign pointers?
No, it just copies the top level structure. CLtL specifically says, "No
attempt is made to make copies of the components." in the description of
:COPIER.
>If the later is true, is there someway of specifying to copy-foo that
>it should copy recursively?
No. If you want a function that does this, you'll have to write your own
COPY-FOO that calls COPY-BAR. If you want something that works for lots of
structure types, use CLOS to implement a generic COPY function that
recurses.
--
Barry Margolin
System Manager, Thinking Machines Corp.
······@think.com {uunet,harvard}!think!barmar
;;If you want something that works for lots of
;;structure types, use CLOS to implement a generic COPY function that
;;recurses.
;;--
;;Barry Margolin
ok, so has anyone done this? I'm going to have to next week if I can't
get such a thing elsewhere...
-- clint
--
Clint Hyde "Give me a LispM or give me death!" -- anonymous
Advanced Decision Systems Internet: ·····@chesapeake.ads.com
2111 Wilson Blvd #800
Arlington, VA 22201 (703) 875-0327
Date: Fri, 7 Aug 1992 19:43 EDT
From: Clinton Hyde <·····@pecos.ads.com>
;;If you want something that works for lots of
;;structure types, use CLOS to implement a generic COPY function that
;;recurses.
;;--
;;Barry Margolin
ok, so has anyone done this? I'm going to have to next week if I can't
get such a thing elsewhere...
-- clint
--
Clint Hyde "Give me a LispM or give me death!" -- anonymous
Advanced Decision Systems Internet: ·····@chesapeake.ads.com
2111 Wilson Blvd #800
Arlington, VA 22201 (703) 875-0327
This works for me on a variety of platforms. There are probably faster
ways to do it under Lucid and Franz, but I don't know them. I haven't
verified recently that the #+CCL-2 case still works.
#+Symbolics
(defun-inline copy-instance (instance)
(clos-internals::%allocate-instance-copy instance))
#+CCL-2 ;Macintosh Common Lisp
(defun copy-instance (instance)
(ccl:without-interrupts
(ccl::copy-uvector
(ccl::%maybe-forwarded-instance instance))))
#-(or Symbolics CCL-2)
(defun copy-instance (instance)
(let* ((class (class-of instance))
(copy (clos:allocate-instance class)))
(dolist (slot (clos:class-slots class))
(let ((name (clos:slot-definition-name slot))
(allocation (clos:slot-definition-allocation slot)))
(when (and (eql allocation :instance)
(slot-boundp instance name))
(setf (slot-value copy name) (slot-value instance name)))))
copy))