Browse code
feat: add hashtable-slot-mixin
Simple base class that provides a doc initarg for
automatically-extracting slots. This works via
`slot-value-using-class` converting the slot name into a (string)
hash-table key.
Showing 1 changed files
... | ... |
@@ -85,3 +85,17 @@ |
85 | 85 |
`(defgeneric ,constructor-name (,@args) |
86 | 86 |
(:method (,@args) |
87 | 87 |
(new ',class ,@args))))) |
88 |
+ |
|
89 |
+(defclass hashtable-slot-mixin () |
|
90 |
+ ((%doc :reader hsm-doc :initarg :doc))) |
|
91 |
+ |
|
92 |
+(defmethod c2mop:slot-value-using-class :before (class (object hashtable-slot-mixin) slotd) |
|
93 |
+ (let ((slot-name (c2mop:slot-definition-name slotd))) |
|
94 |
+ (unless (or (eql slot-name '%doc) |
|
95 |
+ (c2mop:slot-boundp-using-class class object slotd)) |
|
96 |
+ (let* ((doc (hsm-doc object)) |
|
97 |
+ (doc-value (gethash (substitute #\_ #\- |
|
98 |
+ (string-downcase |
|
99 |
+ (symbol-name slot-name))) |
|
100 |
+ doc))) |
|
101 |
+ (setf (slot-value object slot-name) doc-value))))) |