diff options
author | Colin Okay <okay@toyful.space> | 2022-03-12 19:07:19 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-03-12 19:07:19 -0600 |
commit | 50df94fd2a0fce7a2499a8ceafd6034adc69779e (patch) | |
tree | bf9a19a2edf9f2eecf33b9177f99b8e20e73e880 /lib/util.lisp | |
parent | b053af5357bdbcc556e0a54723feceed5091f535 (diff) |
bugfix: s/defstruct/defplist. made defplist
Diffstat (limited to 'lib/util.lisp')
-rw-r--r-- | lib/util.lisp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/util.lisp b/lib/util.lisp index 27f389e..4b827f1 100644 --- a/lib/util.lisp +++ b/lib/util.lisp @@ -70,3 +70,25 @@ determined by EXECUTABLE-ON-SYSTEM-P." "Returns the strings \"true\" or \"false\" depending on whehter or not WHAT is null" (if what "true" "false")) + +(defmacro defplist (name &rest slots) + (let* ((slots-names + (loop for slot in slots + when (symbolp slot) + collect slot + when (consp slot) + collect (first slot))) + (slot-defuns + (loop for slot in slots-names + collect `(defun ,(intern (format nil "~a-~a" name slot)) (,name) + (getf ,name ,(a:make-keyword slot))) + collect `(defun (setf ,(intern (format nil "~a-~a" name slot))) (val ,name) + (setf (getf ,name ,(a:make-keyword slot)) val)))) + (make-name-defun + `(defun ,(intern (format nil "MAKE-~a" name)) (&key ,@slots) + (list ,@(loop for slot in slots-names + collect (a:make-keyword slot) + collect slot))))) + `(progn + ,make-name-defun + ,@slot-defuns))) |