Open vindarel opened 2 months ago
there's something already:
There's a shortcut to setup a basic printing behaviour of a class, using `printing-unreadably`:
```lisp
(printing-unreadably (field2 field3) (class/std myclass field1 field2 field3))
; which expands to:
(PROGN
(CLASS/STD MYCLASS FIELD1 FIELD2 FIELD3)
(DEFMETHOD PRINT-OBJECT ((MYCLASS MYCLASS) #:STREAM1722)
(PRINT-UNREADABLE-OBJECT (MYCLASS #:STREAM1722 :TYPE T :IDENTITY T)
(FORMAT #:STREAM1722 "FIELD2: ~s, FIELD3: ~s"
(FIELD2 MYCLASS) (FIELD3 MYCLASS)))))
but
(FIELD2 MYCLASS) (FIELD3 MYCLASS)
so it uses accessors which may not always be defined and it doesn't check for unbound slots (which wouldn't exist by using defclass/std).(defclass-std:printing-unreadably (field1 field2 field3) (defclass-std:class/std myclass field1 field2 field3))
(make-instance 'myclass :field1 "one")
;; => #<MYCLASS FIELD1: "one", FIELD2: NIL, FIELD3: NIL {1008944E63}>
done: print-object/std
prints all slots.
=>
#<FOO2 {1006584EC3}>
=>
#<FOO2 (BAR NIL), (BAZ NIL) {1006584EC3}>