【发布时间】:2017-03-03 14:19:14
【问题描述】:
我正在尝试创建一个具有 &optional 参数和默认值的 lisp 宏。不幸的是,参数的处理方式不同,具体取决于它是从默认值还是从提供给宏的参数中读取的。下面的代码片段重现了这个问题:
(setf table1 '((1 2 3)
(4 5 6))
table2 '((10 20 30)
(40 50 60)))
(defmacro test-lambda (f &optional (tableau table1))
`(list ,f ,tableau))
? (test-lambda 0 table2) ;; This works...
(0 ((10 20 30) (40 50 60)))
? (test-lambda 0) ;; ...but this doesn't
> Error: Car of ((1 2 3) (4 5 6)) is not a function name or lambda-expression.
> While executing: CCL::CHEAP-EVAL-IN-ENVIRONMENT, in process listener(1).
> Type :POP to abort, :R for a list of available restarts.
> Type :? for other options.
1 >
我不太明白为什么宏在第二种情况下不能使用默认值。有没有更好的方法来编写这个代码或者至少是一种解决方法?
谢谢,
【问题讨论】:
标签: macros lisp common-lisp