Re: How to make a copy of a list



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.
.



Relevant Pages

  • Re: Choice sequence lessons.
    ... and that their right is just as good as the orthodox mathie. ... a whole system of *generating* a sequence. ... interpretations of things - the difference ... vs     NOT ANY of the students will pass. ...
    (sci.logic)
  • Re: The complete infinite binary tree has only countably many infinite paths, says WM.
    ...   That is not what you must do. ... Denote the leading node of any sequence of nodes by its number followed ... In that infinite tree, ...
    (sci.logic)
  • Re: Did I deserve this zero?
    ... Concentrated values in the black suits, comfortable rebid, two unstopped ... Given this sequence,  yes, you deserve the bottom. ... hand and trying to figure out how to bid this hand, ...   Instead you chose a bid that absolutely ...
    (rec.games.bridge)
  • Re: Reinventing the iterator
    ... RST returns the rest of the sequence (lazily) ... The main purpose of SEQ is to give the ability to iterate over various ... just use lists (it's the most simple and ...   "The analog of DOLIST for any collection COLL, ...
    (comp.lang.lisp)
  • Re: Balancing bid
    ...   H: AKQxxxx ... bid 2S over 2C and then bid 4H. ... reasonable on a stiff spade and AX of diamonds. ... I like this sequence best. ...
    (rec.games.bridge)