问题描述
我正在学习实用的 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,docstring
(let ((*test-name* (append *test-name* (list ',@body)))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)