It’s possible the following generic method may work (ie, produce a deep copy of a structure object), although it is not guaranteed to work in every Common Lisp implementation, and certainly is not portable. It does not conform to the Common Lisp Hyperspec, since it tries to apply class functions to structures. But it might be worth a try for personal use.
(defmethod deep-copy ((struct structure-object))
"Copy a structure recursively."
(let ((new-struct (copy-structure struct))
(slots (class-direct-slots (class-of struct))))
(dolist (slot slots)
(let ((slot-name (slot-definition-name slot)))
(setf (slot-value new-struct slot-name)
(deep-copy (slot-value struct slot-name)))))
new-struct))
Use it in the same way you would use copy-list
--ie, (deep-copy my-lisp-object) -> my-lisp-object-copy
. Note however, that this method is only one of several required, since deep-copy needs to recurse over the objects in the structure’s slots, the objects within those objects, etc, until the bottommost immutable objects are reached. These other methods are included in the post at https://codereview.stackexchange.com/questions/156392/generic-copy-function if needed. (Note also, that I’ve changed the name of the methods to deep-copy from ucopy—ie, universal copy). Good luck!