我完全不了解CL,我想学习如何从REPL读取文档字符串和获取其他帮助信息。就像Python中的
例如,在Lisp中,
我希望能看到类似以下的内容:
help(symbol)
或iPython中的symbol?
,还有Haskell的GHCi中的:t
和:i
一样。因此,给定一个符号名称,我想知道以下内容:
- 它绑定的值的种类(函数、变量、没有任何绑定)
- 如果它是一个函数或宏,那么它的位置参数是什么
- 如果有文档字符串,显示它
- 它来自哪个包或文件,或者是什么时候定义的
(documentation '_symbol_ '_type_)
,但这并不完全满足我的需求。在使用documentation
之前,我需要知道符号绑定的值的类型(例如'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).
(documentation 'mapcar 'function)
会显示:"将 FUNCTION 应用于列表的连续元素。返回由 FUNCTION 返回值组成的列表。" - Ken(inspect 'mapcar)
和(describe 'mapcar)
可能是你正在寻找的,但这些函数的实际效用取决于具体的实现方式。 - Daniel Dickisoninspect
和describe
正是我要找的。谢谢。如果你写成答案,我可以接受它。@Ken:我已经安装了CLisp和SBCL,但到现在为止我大多使用CLisp(因为其具有readline功能的REPL对我来说更好)。SBCL的文档字符串确实更有用,但它仍然只是一个文档字符串(还需要找到符号类型和参数列表)。 - sastanin