Common Lisp:获取宏的文档字符串
Common Lisp: Getting the documentation string of a macro
在 SBCL 中,我可以使用如下内容获取函数的文档字符串:
(documentation #'mapcar t)
但是,我不明白如何获取宏的文档字符串。例如,给定宏:
(defmacro with-lines-in-file ((line filename) &body body)
"Runs body for each line in the file specified by filename."
(let ((file (gensym)))
`(with-open-file (,file ,filename)
(do ((,line (read-line ,file nil) (read-line ,file nil)))
((null ,line) nil)
,@body))))
我无法检索文档字符串。我不明白 CLHS。正如您在下面看到的,CLHS 非常适合获取函数的文档字符串。
documentation (x function) (doc-type (eql 't))
但是,从宏中获取文档字符串的位似乎对我不起作用:
documentation (x symbol) (doc-type (eql 'compiler-macro))
在我的宏上下文中,我将上面的 CLHS 位解释为:
(documentation 'with-lines-in-file 'compiler-macro)
但是那个调用 returns NIL。
我正在尝试构建一个函数,为我计划在 GitHub 上共享的 Common Lisp 包创建 README.md 文件。这是一个示例:https://github.com/macnod/dc-utilities. I've written a post about this here: https://donnieknows.com/documenting-common-lisp-for-github/.
Common Lisp 函数的标准说 documentation:
function 如果 x 是函数名称,returns 名称为 x 的函数、宏或特殊运算符的文档字符串。
可以使用参数 function
从中检索文档的三种运算符类型是:
- 函数
- 宏
- 特殊运算符
请记住,在 Common Lisp 中,运算符一次只能是其中之一。
例子
CL-USER> (defmacro foomacro () "foo macro" '(foo))
FOOMACRO
CL-USER> (documentation 'foomacro 'function)
"foo macro"
宏不是编译器宏。这些由 DEFINE-COMPILER-MACRO.
定义
在 SBCL 中,我可以使用如下内容获取函数的文档字符串:
(documentation #'mapcar t)
但是,我不明白如何获取宏的文档字符串。例如,给定宏:
(defmacro with-lines-in-file ((line filename) &body body)
"Runs body for each line in the file specified by filename."
(let ((file (gensym)))
`(with-open-file (,file ,filename)
(do ((,line (read-line ,file nil) (read-line ,file nil)))
((null ,line) nil)
,@body))))
我无法检索文档字符串。我不明白 CLHS。正如您在下面看到的,CLHS 非常适合获取函数的文档字符串。
documentation (x function) (doc-type (eql 't))
但是,从宏中获取文档字符串的位似乎对我不起作用:
documentation (x symbol) (doc-type (eql 'compiler-macro))
在我的宏上下文中,我将上面的 CLHS 位解释为:
(documentation 'with-lines-in-file 'compiler-macro)
但是那个调用 returns NIL。
我正在尝试构建一个函数,为我计划在 GitHub 上共享的 Common Lisp 包创建 README.md 文件。这是一个示例:https://github.com/macnod/dc-utilities. I've written a post about this here: https://donnieknows.com/documenting-common-lisp-for-github/.
Common Lisp 函数的标准说 documentation:
function 如果 x 是函数名称,returns 名称为 x 的函数、宏或特殊运算符的文档字符串。
可以使用参数 function
从中检索文档的三种运算符类型是:
- 函数
- 宏
- 特殊运算符
请记住,在 Common Lisp 中,运算符一次只能是其中之一。
例子
CL-USER> (defmacro foomacro () "foo macro" '(foo))
FOOMACRO
CL-USER> (documentation 'foomacro 'function)
"foo macro"
宏不是编译器宏。这些由 DEFINE-COMPILER-MACRO.
定义