From 50df94fd2a0fce7a2499a8ceafd6034adc69779e Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 12 Mar 2022 19:07:19 -0600 Subject: bugfix: s/defstruct/defplist. made defplist --- lib/util.lisp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/util.lisp') 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))) -- cgit v1.2.3