Common Lisp:获取宏的文档字符串 [英] Common Lisp: Getting the documentation string of a macro

查看:91
本文介绍了Common Lisp:获取宏的文档字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SBCL中,我可以使用以下内容获取函数的文档字符串:

In SBCL, I can get the documentation string for a function with something like this:

(documentation #'mapcar t)

但是,我不明白如何获取宏的文档字符串.例如,给定宏:

However, I don't understand how to get the documentation string for a macro. For example, given the macro:

(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在获取函数的文档字符串方面做得很好.

I'm not able to retrieve the documentation string. I don't understand the CLHS. As you can see below, the CLHS worked great for obtaining the documentation string for a function.

documentation (x function) (doc-type (eql 't))

但是,从宏那里获取文档字符串的部分似乎对我不起作用:

However, the bit for obtaining the documentation string from a macro doesn't seem to work for me:

documentation (x symbol) (doc-type (eql 'compiler-macro))

在我的宏上下文中,我将上面的CLHS解释为:

In the context of my macro, I'm interpreting the above CLHS bit to mean this:

(documentation 'with-lines-in-file 'compiler-macro)

但是该调用返回NIL.

But that call returns NIL.

我正在尝试构建一个函数,该函数为计划在GitHub上共享的Common Lisp软件包创建README.md文件.这是一个示例: https://github.com/macnod/dc-utilities .我在这里写过一篇文章: https://donnieknows.com/documenting -common-lisp-for-github/.

I'm trying to build a function that creates the README.md file for the Common Lisp packages that I plan to share on GitHub. Here's an example: https://github.com/macnod/dc-utilities. I've written a post about this here: https://donnieknows.com/documenting-common-lisp-for-github/.

推荐答案

该标准表示Common Lisp函数文档:

The standard says for the Common Lisp function documentation:

函数 如果x是函数名称,则返回名称为x的函数,宏或特殊运算符的文档字符串.

一个可以从中检索文档的三种运算符类型,参数为function分别是:

The three operator types one can retrieve documentation from, with the argument function are thus:

  • 功能
  • 特殊运营商

请记住,在Common Lisp中,操作员一次只能是其中之一.

Remember, in Common Lisp an operator can only be one of those at a time.

示例

CL-USER> (defmacro foomacro () "foo macro" '(foo))
FOOMACRO
CL-USER> (documentation 'foomacro 'function)
"foo macro"

宏不是编译器宏.这些是由 DEFINE-COMPILER-MACRO 定义的

Macros are not compiler macros. Those are defined by DEFINE-COMPILER-MACRO.

这篇关于Common Lisp:获取宏的文档字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆