diff --git a/kutils.asd b/kutils.asd index 37e9dd4..a32bc63 100644 --- a/kutils.asd +++ b/kutils.asd @@ -5,6 +5,7 @@ :author "K. Isom " :license "MIT License" :serial t + :depends-on (#:closer-mop) :components ((:file "package") (:file "on") (:file "lol") diff --git a/kutils.lisp b/kutils.lisp index 4f6a842..ef80332 100644 --- a/kutils.lisp +++ b/kutils.lisp @@ -75,11 +75,18 @@ additional args provided to the lambda." '() (apply #'build-slot-list name slots))) (args (build-arg-list slots))) - `(progn - (defclass ,name ,superclass - ,slots - ,docstring - ,@body)))) + `(defclass ,name ,superclass + ,slots + ,docstring + ,@body))) + +(defmacro defconstructor (class-name) + (let* ((class (find-class class-name)) + (slot-list (when class + (mapcar #'closer-mop:slot-definition-name + (closer-mop:class-slots class))))) + `(defun ,(mksymb "make-" class-name) (&key ,@slot-list) + (make-instance ',class-name ,@(flatten (build-arg-list slot-list)))))) ;;; hash-table functions. diff --git a/package.lisp b/package.lisp index 79132da..fff52a8 100644 --- a/package.lisp +++ b/package.lisp @@ -15,6 +15,7 @@ #:mksymb #:mkkw #:defclass! + #:defconstructor #:enable-hash-table-reader #:hashkeys #:sethash