【问题标题】:How to see doc string for a defparameter, defconstant, or defvar?如何查看 defparameter、defconstant 或 defvar 的文档字符串?
【发布时间】:2016-10-18 15:31:55
【问题描述】:

使用 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

【问题讨论】:

    标签: common-lisp sbcl


    【解决方案1】:

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

    【讨论】:

    • 所以它是一个变量,谢谢我以为它是一个符号
    猜你喜欢
    • 2012-02-14
    • 2012-02-18
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    相关资源
    最近更新 更多