我正在通过 Practical Common Lisp 工作。我得到了一个例子,你定义了一个与一些附加功能deftest
类似的宏。defun
这让我想到能够添加一个文档字符串会很好。我发现以下两项都有效,但其中一项更正确吗?是否有一种“正确”的方式来实现类似可选文档字符串的行为defun
?
(defmacro deftest (name parameters &body body)
(let ((docstring ""))
(when (stringp (car body)) (setf docstring (car body) body (cdr body)))
`(defun ,name ,parameters
,docstring
(let ((*test-name* (append *test-name* (list ',name))))
,@body))))
(defmacro deftest (name parameters &optional docstring &body body)
(when (not (stringp docstring)) (setf docstring ""))
`(defun ,name ,parameters
,docstring
(let ((*test-name* (append *test-name* (list ',name))))
,@body)))