我需要为可以读取此语法的元循环解释器创建函数 defmacro:
pseudoscheme> (defmacro (minus x y) (list ‘- y x))
MINUS
pseudoscheme> (expand-macro '(minus 3 2))
(- 3 2)
当我使用这个时:
(defmacro my-defmacro ((name &rest args) &body body)
(let ((form (gensym))(env (gensym)))
(progn
`(setf (macro-function ',name)
(lambda (,form ,env))
(destructuring-bind ,args (rest, form) ,@body))
name
)
)
)
接着:
(my-defmacro (min a b)(list '- a b))
我收到此错误:
Error: The variable MIN is unbound.
我不明白为什么。
-----已编辑----- 如果我使用这个:
(defmacro my-defmacro ((name &rest args) &body body)
(let ((form (gensym))(env (gensym)))
`(progn (setf (macro-function ',name)
(lambda (,form ,env))
(destructuring-bind ,args (rest, form) ,@body))
',name)
)
)
接着:
(my-defmacro (min a b)(list '- a b))
我收到此错误:
Error: Odd number of args to SETF: ((MACRO-FUNCTION (QUOTE PLUS)) (LAMBDA (#:G786 #:G787)) (DESTRUCTURING-BIND (A B) (REST #:G786) (LIST # A B)))