Search code examples
documentationlispcommon-lispread-eval-print-loop

How to see docstrings and other symbol information in Common Lisp REPL?


I'm completely new to CL, and I'd like to learn how to read documentation strings and get other help information from the REPL. Something like help(symbol) in Python, or symbol? in iPython, or :t and :i in Haskell's GHCi.

So, given a symbol name, I'd like to be able to know:

  • what kind of value it is bound to, if any (a function, a variable, none at all)
  • if it is a function or a macro, then what are its positional arguments
  • if it has a docstring, show it
  • what package or file it is coming from or when it was defined

I found there is (documentation '_symbol_ '_type_), but it is not exactly what I need. I need to know the type of value the symbol is bound to ('function, 'variable, 'compiler-macro, etc.) before I can use documentation. Then it returns only the docstring, it may be missing or not sufficient to use the symbol.

For example, in Lisp, the help for mapcar is not very useful (CLisp's REPL):

> (documentation 'mapcar 'function)
NIL

I'd like to be able to see something like this instead:

>>> map?
Type:       builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form:    <built-in function map>
Namespace:  Python builtin
Docstring:
    map(function, sequence[, sequence, ...]) -> list

    Return a list of the results of applying the function to the items of
    the argument sequence(s).  If more than one sequence is given, the
    function is called with an argument list consisting of the corresponding
    item of each sequence, substituting None for missing values when not all
    sequences have the same length.  If the function is None, return a list of
    the items of the sequence (or a list of tuples if more than one sequence).

Solution

  • As mentioned Common Lisp has standard functions: DESCRIBE, INSPECT and DOCUMENTATION. Typical Lisp IDEs also have these bound to keys and menus.

    For standard Common Lisp functionality most IDEs directly link to the Common Lisp HyperSpec documentation with a keystroke.

    Most IDEs also have keystrokes to show the arglist and the documentation. There is also the 'arglist on space' functionality.

    LispWorks specific examples: LispWorks Argument list information and LispWorks Expressions menu

    I can recommend to read the IDE manual for Slime, LispWorks Editor, Allegro CL's ELI, or whatever IDE you are using.