Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see doc string for a defparameter, defconstant, or defvar?

Using common lisp you can add many docs strings for example:

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

so finally I can read the doc string back, but with symbols and variables I cannot get it back with documentation:

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

So it is wrong the type 'symbol, or which type I would use. I'm not sure what really happens

I'm using: SBCL 1.3.10

like image 660
anquegi Avatar asked Oct 18 '16 15:10

anquegi


People also ask

What is Defvar Lisp?

In Emacs Lisp, a variable such as the kill-ring is created and given an initial value by using the defvar special form. The name comes from “define variable”. The defvar special form is similar to setq in that it sets the value of a variable.

What is Defparameter in Common Lisp?

defparameter unconditionally assigns the initial-value to the dynamic variable named name. defvar, by contrast, assigns initial-value (if supplied) to the dynamic variable named name only if name is not already bound.


1 Answers

Let's have a look at the doc of 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.
[...]"

And so:

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

See documentation for details.

like image 140
coredump Avatar answered Sep 22 '22 02:09

coredump