|
100 | 100 | (defgeneric initialize-clone (old new &rest initargs &key &allow-other-keys)
|
101 | 101 | (:documentation
|
102 | 102 | "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 |
104 | 104 | slot values and preclude unwanted deep cloning.")
|
105 | 105 |
|
106 | 106 | (:method ((old standard-object) (new standard-object) &rest initargs)
|
107 | 107 | (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) |
109 | 113 |
|
110 | 114 | (:method ((from simple-condition) (to simple-condition) &rest
|
111 | 115 | de.setf.utility.implementation::initargs &key
|
|
138 | 142 | slots with bound values are left unchanged in order to permit previous initarg
|
139 | 143 | based initialization (see clone-instance), which can then avoid unwanted deep
|
140 | 144 | 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 | + )) |
142 | 149 |
|
143 | 150 |
|
144 |
| -(defmacro defcopy-instance-slots ((class &rest slot-names) &rest body) |
| 151 | +(defmacro def-copy-instance-slots (class slot-names &rest body) |
145 | 152 | `(defmethod copy-instance-slots progn ((from ,class) (to ,class))
|
146 | 153 | ,@(mapcar #'(lambda (slot-name)
|
147 | 154 | `(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))))) |
150 | 158 | slot-names)
|
151 | 159 | ,@body
|
152 | 160 | to))
|
|
0 commit comments