Plaster

common-lisp
(defclass item () ((question :accessor question :initarg :question) (answer :accessor answer :initarg :answer) (easing-factor :accessor easing-factor :initform 2.5) (repetitions :accessor repetitions :initform 0))) (defun item-plist (item) (let* ((slots (sb-mop:class-slots (class-of item))) (names (mapcar #'sb-mop:slot-definition-name slots))) (loop for name in names collect (alexandria:symbolicate name) collect (slot-value item name)))) (defmethod print-object ((object item) stream) (cond (*print-readably* (format stream "#.") (pprint `(make-instance ',(class-name (class-of object)) ,@(item-plist object)) stream)) (t (call-next-method)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CL-USER> (make-instance 'item :question "Where?" :answer "There.") #. (MAKE-INSTANCE 'ITEM QUESTION "Where?" ANSWER "There." EASING-FACTOR 2.5 REPETITIONS 0)