Re: How to make a copy of a list
- From: Kaz Kylheku <kkylheku@xxxxxxxxx>
- Date: Tue, 29 Apr 2008 20:19:59 -0700 (PDT)
On Apr 29, 4:46 pm, Trastabuga <lisper...@xxxxxxxxx> wrote:
On Apr 29, 5:54 pm, "John Thingstad" <jpth...@xxxxxxxxx> wrote:
(defun deep-copy-sequence (sequence)
"Recursivly copy all array's and list's."
(cond
((arrayp sequence)
(setf sequence (copy-seq sequence))
(loop for element across sequence
when (subtypep (type-of element) 'sequence)
do (setf element (deep-copy-sequence element))))
((listp sequence)
(setf sequence (copy-list sequence))
(loop for element in sequence
when (subtypep (type-of element) 'sequence)
do (setf element (deep-copy-sequence element)))))
sequence)
--------------
John Thingstad
John, your original version of deep-copy-sequence works, but the
latest doesn't (the original list gets changed).
The problem is that the (SETF ELEMENT ...) expressions in the LOOP-s
don't do what is intended. ELEMENT is a local variable, not a symbol
macro covering the original storage place within the sequence.
.
- Follow-Ups:
- Re: How to make a copy of a list
- From: John Thingstad
- Re: How to make a copy of a list
- References:
- How to make a copy of a list
- From: Trastabuga
- Re: How to make a copy of a list
- From: John Thingstad
- Re: How to make a copy of a list
- From: John Thingstad
- Re: How to make a copy of a list
- From: John Thingstad
- Re: How to make a copy of a list
- From: Trastabuga
- How to make a copy of a list
- Prev by Date: Re: Scope Question
- Next by Date: Re: postmodern thread safety in prepared statements functionality
- Previous by thread: Re: How to make a copy of a list
- Next by thread: Re: How to make a copy of a list
- Index(es):
Relevant Pages
|