Browse code
feat: add define-printer
Edward Langley authored on 23/04/2023 17:13:54
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -115,3 +115,13 @@ |
115 | 115 |
(symbol-name slot-name))) |
116 | 116 |
doc))) |
117 | 117 |
(setf (slot-value object slot-name) doc-value))))) |
118 |
+ |
|
119 |
+ |
|
120 |
+(defmacro define-printer (class &body options) |
|
121 |
+ (alexandria:with-gensyms (s) |
|
122 |
+ `(defmethod print-object ((,class ,class) ,s) |
|
123 |
+ (print-unreadable-object (,class ,s :type t :identity t) |
|
124 |
+ ,(destructuring-bind (name value) (car options) |
|
125 |
+ `(format ,s "~a: ~s" ,name (,value ,class))) |
|
126 |
+ ,@(loop for (name value) in (cdr options) |
|
127 |
+ collect `(format ,s ", ~a: ~s" ,name (,value ,class))))))) |
... | ... |
@@ -32,7 +32,7 @@ |
32 | 32 |
#:defun-ct :define-cluser-entrypoint :new :make-constructor |
33 | 33 |
#:dive :empty-hash-table-like :v-assoc :defclass+ :closing |
34 | 34 |
#:inits :retry-once :hashtable-slot-mixin :hsm-doc :adjoinf |
35 |
- #:it :keys :split-at)) |
|
35 |
+ #:it :keys :split-at :define-printer)) |
|
36 | 36 |
|
37 | 37 |
|
38 | 38 |
(defpackage :fwoar.lisputils.shortcuts |