copying list of structs in common lisp

common-lisp, copy, list, pass-by-value, struct

Solution

There is little value to have that function pre-defined.

Your code is just:

(mapcar #'copy-structure some-list)

Problem

I have a list of structs, and I want to write a function that alters some slots in the structs without affecting the original list. I tried using copy-list, but its not deep enough; the slot values are also altered in the original list. My question is, is there a built-in function that does what I want?, or should I write my own one?. Thank you. EDIT: I went on and wrote my own function, is there a built-in one that would do this though? ``` (defun deep-copy (li) (if (null li) nil (cons (copy-structure (car li)) (deep-copy (rest li))))) ```

Original source