common-lisp - 如何查看defparameter,defconstant或defvar的文档字符串?

标签 common-lisp sbcl

使用通用Lisp,您可以添加许多docs字符串,例如:

CL-USER> (defun foo ()
           "doc string for foo"
           nil)
FOO
CL-USER> (documentation 'foo 'function)
"doc string for foo"

CL-USER> (describe 'foo)
COMMON-LISP-USER::FOO
  [symbol]

FOO names a compiled function:
  Lambda-list: ()
  Derived type: (FUNCTION NIL (VALUES NULL &OPTIONAL))
  Documentation:
    doc string for foo
  Source form:
    (SB-INT:NAMED-LAMBDA FOO
        NIL
      "doc string for foo"
      (BLOCK FOO NIL))
; No value
所以最终我可以读回文档字符串,但是使用符号和变量我无法通过文档将其取回:
CL-USER> (defparameter bar 3 "doc string for bar")
BAR
CL-USER> (describe 'bar)
COMMON-LISP-USER::BAR
  [symbol]

BAR names a special variable:
  Value: 3
  Documentation:
    doc string for bar
; No value
CL-USER> (documentation 'bar 'symbol)
WARNING: unsupported DOCUMENTATION: doc-type SYMBOL for object of type SYMBOL
NIL
因此类型'symbol或我将使用哪种类型是错误的。我不确定到底会发生什么
我正在使用:SBCL 1.3.10

最佳答案

让我们看看documentation的文档;-)

CL-USER> (documentation 'documentation 'function)
"Return the documentation string of Doc-Type for X, or NIL if none
exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE, SETF, and T.
[...]"

所以:
CL-USER> (documentation 'bar 'variable)
"doc string for bar"

有关详细信息,请参见 documentation

关于common-lisp - 如何查看defparameter,defconstant或defvar的文档字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40112343/

相关文章:

performance - Common Lisp,尤其是SBCL中线性代数的高效向量运算?

ipython - Jupyter 和 Common Lisp

format - sbcl 将有理数转换为十进制时尽可能保持精度

common-lisp - sbcl - 如何消除 "undefined variable"警告?

scheme - 是否有与 SBCL 的运行程序等效的方案?

common-lisp - 如何将所有函数和包声明包含在一个名为 all.lisp 的文件中,用于 asdf 包推断系统

common-lisp - 用于检查参数和其他偏执狂的常见Lisp习语?

common-lisp - 从 key 代码中解析出 key

lisp - "Define"在我的 lisp 编译器(Steel Bank Common Lisp)中未定义

emacs - SLIME、SBCL 和 EMACS 设置未产生预期的输出