27

我对 CL 完全陌生,我想学习如何阅读文档字符串并从 REPL 获取其他帮助信息。类似于help(symbol)Python、symbol?iPython 或:tHaskell:i的 GHCi 中的东西。

所以,给定一个符号名称,我想知道:

  • 它绑定到什么样的值,如果有的话(一个函数,一个变量,根本没有)
  • 如果它是一个函数或一个宏,那么它的位置参数是什么
  • 如果它有一个文档字符串,显示它
  • 它来自什么包或文件或何时定义

我发现有(documentation '_symbol_ '_type_),但这不是我所需要的。在我可以使用'function. 然后它只返回文档字符串,它可能丢失或不足以使用该符号。'variable'compiler-macrodocumentation

例如,在 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).
4

2 回答 2

29

如前所述,Common Lisp 具有标准功能:DESCRIBEINSPECTDOCUMENTATION。典型的 Lisp IDE 也将这些绑定到键和菜单。

对于标准的 Common Lisp 功能,大多数 IDE 通过按键直接链接到 Common Lisp HyperSpec 文档。

大多数 IDE 也有按键来显示 arglist 和文档。还有“空间上的 arglist”功能。

LispWorks 特定示例:LispWorks 参数列表信息LispWorks 表达式菜单

我可以推荐阅读SlimeLispWorks EditorAllegro CL 的 ELI或您正在使用的任何 IDE 的 IDE 手册。

于 2011-02-23T16:32:39.540 回答
8

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.

于 2011-02-23T20:16:59.663 回答