program-saver/asd.lisp

32 lines
970 B
Common Lisp

(progn
(defun add (a b) (+ a b))
(defvar whatever 16))
;; struct
(progn
(defun constructor-name (sym)
(intern (concatenate 'string "MAKE-" (string sym))))
(defun accessor-name (name sym)
(intern (concatenate 'string (string name) "-" (string sym))))
(defun setter-name (name sym)
(intern (concatenate 'string "SET-" (string name) "-" (string sym))))
(defmacro mydefstruct (name &rest slots)
`(progn
(defun ,(constructor-name name)
,slots
(list ,@slots))
,@(loop for i from 0 to (1- (length slots)) collect
`(defun ,(accessor-name name (nth i slots))
(instance)
(nth ,i instance)))
,@ (loop for i from 0 to (1- (length slots)) collect
`(defun ,(setter-name name (nth i slots))
(instance val)
(setf (nth ,i instance) val)))
,@(loop for i from 0 to (1- (length slots)) collect
`(defsetf ,(accessor-name name (nth i slots))
,(setter-name name (nth i slots)))))))