lisp - Creating a keyword symbol -
i'm trying create macro takes keyword parameters and, if parameter defined, add entries list. splitting following code should illustrate need.
(defun add-if-not-null (var lst) (if (not (null var)) (append (cons (***) (cons ver '())) lst)))
the 3 asterisks show part i'm trying figure out. takes symbol name , turns keyword representation. e.g. width converts :width
(let ((width 100)) (add-if-not-null (width '())))
should return
(:width 100)
i'm using cl-who create svg representation , want set attributes width , height if specified parameters macro wraps document.
the name of package keyword
. symbols created (if necessary) , put package using intern
.
cl-user 11 > (intern (symbol-name 'width) "keyword") :width
a macro:
cl-user 29 > (defmacro add-if-not-null (var list) (check-type var symbol) `(when var (push (list ,(intern (symbol-name var) "keyword") var) ,list))) add-if-not-null cl-user 30 > (macroexpand-1 '(add-if-not-null width some-list)) (when var (push (list :width var) some-list)) t
Comments
Post a Comment