2011-05-27 63 views
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. 

是否有任何流行的方案開發環境的任何等同於Python的交互式help命令? (我一直在DrScheme工作,但我願意切換到球拍,MITScheme等,只要我仍然可以在最小調整的情況下完成SICP中的所有練習。)

另外,是否有相當於dir(__builtins__)命令,該命令將列出Scheme中定義的所有可用過程?能夠快速說出給定的語言選擇或給定的包所定義的內容是很好的。

回答

2

更新的回答:因爲我寫了上面的回答,我認爲整合「互動黑客」進入主樹(通過夜間的可用版本,並會成爲下一個球拍釋放(明年十月)的一部分)。這個問題的答案,在球拍的背景下,現在是:

  • 安裝xrepl - 最簡單的方法是(require xrepl),然後使用,install!命令在初始化文件進行安裝。

  • 您問題的第一部分的答案現在是​​命令:只需使用任何綁定,您將在其文檔中獲得一個瀏覽器窗口。

  • 第二部分的答案是使用,ap - 沒有參數可以看到當前命名空間中可用的所有標識符,並且只有一個參數會顯示匹配的名稱。

2

對於球拍,可以使用namespace-mapped-symbols功能。例如,看到我"interactive hack"它給你特別的REPL命令,包括,apropos通過目前已知的綁定進行搜索。 (請參閱有關如何使用它的說明文件。)

4

這將是對每個方案不同(不像Common Lisp的,其中有描述了內置)。例如,在Chicken中,您可以使用chicken-doc擴展名,讓您從命令行和REPL中瀏覽文檔。

+0

Common Lisp的說到是有目錄(\ _ \ _建宏\ _ \ _)一個簡單的解決方案? – whoplisp 2011-08-03 15:41:30

+1

最接近的匹配可能是使用do-symbols或do-external-symbols遍歷包中的符號。 Doc:http://www.lispworks.com/documentation/HyperSpec/Body/m_do_sym.htm 示例:http://cl-cookbook.sourceforge.net/packages.html – Shaun 2011-08-03 18:14:19

2

在麻省理工學院的計劃:

(environment-bindings system-global-environment)