Browse code
feature: add defclass+ macro
Showing 1 changed files
... | ... |
@@ -21,6 +21,29 @@ |
21 | 21 |
_1)) |
22 | 22 |
initializer-syms))))) |
23 | 23 |
|
24 |
+(defmacro defclass+ (name (&rest super) &body (direct-slots &rest options)) |
|
25 |
+ (let ((initargs (append (mapcan (lambda (class) |
|
26 |
+ (typecase class |
|
27 |
+ (cons (cadr class)) |
|
28 |
+ (t nil))) |
|
29 |
+ super) |
|
30 |
+ (mapcan (lambda (slot) |
|
31 |
+ (alexandria:ensure-list |
|
32 |
+ (alexandria:when-let ((initarg (getf (cdr slot) |
|
33 |
+ :initarg))) |
|
34 |
+ (make-symbol (symbol-name initarg))))) |
|
35 |
+ direct-slots)))) |
|
36 |
+ `(progn (defclass ,name |
|
37 |
+ ,(mapcar (lambda (it) |
|
38 |
+ (typecase it |
|
39 |
+ (cons (car it)) |
|
40 |
+ (t it))) |
|
41 |
+ super) |
|
42 |
+ ,direct-slots |
|
43 |
+ ,@options) |
|
44 |
+ (defun ,name (,@initargs) |
|
45 |
+ (fw.lu:new ',name ,@initargs))))) |
|
46 |
+ |
|
24 | 47 |
(defun-ct %constructor-name (class) |
25 | 48 |
(format nil "~a-~a" '#:make class)) |
26 | 49 |
|