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

只愿长相守 提交于 2019-11-29 05:24:30

问题


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).

回答1:


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.




回答2:


Regarding your question about getting the type of symbol: there is no such thing. Or, more precisely, symbols are not just names of other objects, but themselves objects of the type SYMBOL. Each symbol can have both a variable value and a function value. To check if it has a variable value, use BOUNDP, and to check for a function value FBOUNDP.



来源:https://stackoverflow.com/questions/5093513/how-to-see-docstrings-and-other-symbol-information-in-common-lisp-repl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!