Skip to content

Commit ec7080d

Browse files
committed
use def- convention for all clone-instance utilities macros
1 parent e98a2ac commit ec7080d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

clos/clone-instance.lisp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,16 @@
100100
(defgeneric initialize-clone (old new &rest initargs &key &allow-other-keys)
101101
(:documentation
102102
"invoke shared-initialize with initargs to initialize slots
103-
prior to copying from the instance to the clonein order to override the existing
103+
prior to copying from the instance to the clone in order to override the existing
104104
slot values and preclude unwanted deep cloning.")
105105

106106
(:method ((old standard-object) (new standard-object) &rest initargs)
107107
(declare (dynamic-extent initargs))
108-
(apply #'shared-initialize new t initargs)) ;; must pass t to get default initform protocol
108+
(apply #'shared-initialize new t initargs) ;; must pass t to get default initform protocol
109+
;; after running shared initialize and between specialization next-method calls
110+
;; perform any standard slot copying
111+
(copy-instance-slots old new)
112+
new)
109113

110114
(:method ((from simple-condition) (to simple-condition) &rest
111115
de.setf.utility.implementation::initargs &key
@@ -138,15 +142,19 @@
138142
slots with bound values are left unchanged in order to permit previous initarg
139143
based initialization (see clone-instance), which can then avoid unwanted deep
140144
cloning.")
141-
(:method-combination progn :most-specific-first))
145+
(:method-combination progn :most-specific-first)
146+
(:method progn ((old standard-object) (new standard-object))
147+
;; the base method does nothing
148+
))
142149

143150

144-
(defmacro defcopy-instance-slots ((class &rest slot-names) &rest body)
151+
(defmacro def-copy-instance-slots (class slot-names &rest body)
145152
`(defmethod copy-instance-slots progn ((from ,class) (to ,class))
146153
,@(mapcar #'(lambda (slot-name)
147154
`(unless (slot-boundp to ',slot-name)
148-
(setf (slot-value to ',slot-name)
149-
(slot-value from ',slot-name))))
155+
(when (slot-boundp from ',slot-name)
156+
(setf (slot-value to ',slot-name)
157+
(slot-value from ',slot-name)))))
150158
slot-names)
151159
,@body
152160
to))

0 commit comments

Comments
 (0)