+(export 'instance-initargs)
+(defgeneric instance-initargs (instance)
+ (:documentation
+ "Return a plausble list of initargs for INSTANCE.
+
+ The idea is that you can make a copy of INSTANCE by invoking
+
+ (apply #'make-instance (class-of INSTANCE)
+ (instance-initargs INSTANCE))
+
+ The default implementation works by inspecting the slot definitions and
+ extracting suitable initargs, so this will only succeed if enough slots
+ actually have initargs specified that `initialize-instance' can fill in
+ the rest correctly.
+
+ The list returned is freshly consed, and you can destroy it if you like.")
+ (:method ((instance standard-object))
+ (mapcan (lambda (slot)
+ (aif (slot-definition-initargs slot)
+ (list (car it)
+ (slot-value instance (slot-definition-name slot)))
+ nil))
+ (class-slots (class-of instance)))))
+