如何查看 defparameter、defconstant 或 defvar 的文档字符串?

7
使用Common Lisp,您可以添加许多文档字符串,例如:
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

1个回答

12

让我们来看看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"

请参阅文档了解详情。


1
所以它是一个变量,谢谢,我一直以为它是一个符号。 - anquegi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接