如何在 Common Lisp REPL 中查看文档字符串和其他符号信息?
我对 CL 完全陌生,我想学习如何阅读文档字符串并从 REPL 获取其他帮助信息。类似于 Python 中的 help(symbol)
,或 iPython 中的 symbol?
,或 :t
和 :i
哈斯克尔的 GHCi。
因此,给定一个符号名称,我希望能够知道:
- 它绑定到什么类型的值,如果有的话(函数,变量,根本没有)
- 如果它是函数或宏,那么什么是它的位置参数(
- 如果它有文档字符串),显示
- 它来自哪个包或文件,或者定义它的时间
我发现有 (documentation '_symbol_ '_type_)
,但它并不完全是我需要。我需要先知道符号绑定到的值的类型('function
、'variable
、'compiler-macro
等)我可以使用文档
。然后它仅返回文档字符串,它可能会丢失或不足以使用该符号。
例如,在 Lisp 中,mapcar
的帮助不是很有用(CLisp 的 REPL):
> (documentation 'mapcar 'function)
NIL
我希望能够看到类似这样的内容:
>>> 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).
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如前所述,Common Lisp 具有标准函数:DESCRIBE、INSPECT 和 文档。典型的 Lisp IDE 也将它们绑定到按键和菜单。
对于标准 Common Lisp 功能,大多数 IDE 通过按键直接链接到 Common Lisp HyperSpec 文档。
大多数 IDE 还可以通过击键来显示参数列表和文档。还有“空间参数列表”功能。
LispWorks 具体示例: LispWorks 参数列表信息和LispWorks表达式菜单
我建议阅读 Slime 的 IDE 手册, LispWorks 编辑器, Allegro CL 的 ELI,或您正在使用的任何 IDE。
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.
关于您有关获取符号类型的问题:没有这样的事情。或者,更准确地说,符号不仅仅是其他对象的名称,而且本身也是 符号。每个符号可以同时具有变量值和函数值。要检查它是否具有变量值,请使用 BOUNDP,并且检查函数值FBOUNDP。
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.