lisp - How can I destructure an &rest argument of varying length in my elisp macro? -
lisp - How can I destructure an &rest argument of varying length in my elisp macro? -
i have programme takes inputs chunk of info , list of rules, applying both set of standard rules , rules given input chunk of data. size of both inputs may vary.
i want able write list of rules this:
class="lang-lisp prettyprint-override">(rule-generating-macro (rule-1-name rule-1-target (rule-action-macro (progn actions more-actions))) (rule-2-name rule-2-target (rule-action-macro (or (action-2) (default-action)))) ;; more rules )
right now, rules more verbose -- more
class="lang-lisp prettyprint-override">(defvar rule-list `((rule-1-name rule-1-target ,@(rule-action-macro (progn actions more-actions))) (rule-2-name rule-2-target ,@(rule-action-macro (or (action-2) (default-action)))) ;; more rules )
the latter form looks uglier me, can't figure out how write macro can handle variable-length &rest
argument, iterate on it, , homecoming transformed structure. using defun
instead of defmacro
isn't on table because (as illustration shows) i'm trying command evaluation of list of rules instead of evaluating list when programme first sees it, , 1 time need command evaluation, you're in defmacro
territory. in case, thorny point rule-action-macro
part - getting interpreter read , utilize expanded value has been problematic.
how can create macro handles variable-length argument can write rule lists in concise way?
defmacro
happily take &rest
argument (see defining macros emacs lisp , macro lambda lists mutual lisp).
then can pretty much want in macro body - e.g., iterate on it. remember, macro much more backquote!
e.g.:
(defmacro multidefvar (&rest vars) (let ((forms (mapcar (lambda (var) `(defvar ,var)) vars))) `(progn ,@forms))) (macroexpand '(multidefvar b c d)) ==> (progn (defvar a) (defvar b) (defvar c) (defvar d))
macros lisp elisp
Comments
Post a Comment