Re: How to make a copy of a list
- From: "John Thingstad" <jpthing@xxxxxxxxx>
- Date: Wed, 30 Apr 2008 07:21:32 +0200
På Wed, 30 Apr 2008 05:19:59 +0200, skrev Kaz Kylheku <kkylheku@xxxxxxxxx>:
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.
DUH! right..
(loop for rest over sequence do (setf (car rest) (deep-copy-sequence (car rest)))
might fare better.
--------------
John Thingstad
.
- 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
- Re: How to make a copy of a list
- From: Kaz Kylheku
- How to make a copy of a list
- Prev by Date: Questions - Higer Order Functions
- Next by Date: Re: How to make a copy of a list
- 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):