2

在 Python 的交互式 shell 中,您可以使用命令获取内置函数列表(如果您知道在哪里查找)dir

>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']

一旦您知道函数名称,您就可以使用该help命令获得有关任何函数的交互式帮助。

>>> help(input)
Help on built-in function input in module builtins:

input(...)
    input([prompt]) -> string

    Read a string from standard input.  The trailing newline is stripped.
    If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
    On Unix, GNU readline is used if enabled.  The prompt string, if given,
    is printed without a trailing newline before reading.

help在任何流行的 Scheme 开发环境中,Python 的交互式命令是否有任何等价物?(我一直在 DrScheme 工作,但我愿意切换到 Racket、MITScheme 等,只要我仍然可以在 SICP 中以最少的调整完成所有练习

另外,是否有一个等效的dir(__builtins__)命令可以列出 Scheme 中定义的所有可用过程?如果能够快速判断给定语言选择或给定包的定义,那就太好了。

4

4 回答 4

4

对于每个方案,这将是不同的(与内置描述的 Common Lisp 不同)。例如,在 Chicken 中,您可以使用chicken-doc扩展,让您可以从命令行和 REPL 浏览文档。

于 2011-05-27T12:48:28.710 回答
2

在 MIT 计划中:

(environment-bindings system-global-environment)
于 2011-07-31T13:40:16.790 回答
2

对于球拍,您可以使用该namespace-mapped-symbols功能。例如,请参阅我的“交互式黑客”,它为您提供了特殊的 REPL 命令,apropos,包括搜索当前已知的绑定。(有关如何使用它的说明,请参阅文件。)

于 2011-05-27T00:43:05.077 回答
2

更新的答案:因为我写了上面的答案,我已经将“交互式黑客”集成到主树中(可通过每晚构建获得,并将成为下一个 Racket 版本(明年 10 月)的一部分)。在 Racket 的上下文中,这个问题的答案现在是:

  • 安装xrepl——最简单的方法是(require xrepl)然后使用,install!命令将其安装到您的初始化文件中。

  • 您问题第一部分的答案现在是,doc命令:只需使用任何绑定,您就会在其文档中获得一个浏览器窗口。

  • 第二部分的答案是使用,ap-- 不带参数,您将看到当前命名空间中可用的所有标识符,带参数它将仅显示匹配的名称。

于 2011-07-28T17:21:07.847 回答