4

我在 shell 中工作,我想查看函数的帮助io:format/1

我的思路如下:

  1. 执行help()- 我找到命令m().
  2. 执行m(io)- 我看到io模块中的函数列表

问题:如何io:format/1从 erlang Shell 深入查找函数的帮助?


输出help().

1> help().
...
m(Mod)     -- information about module <Mod>
memory()   -- memory allocation information
...
true

输出m(io).

2> m(io).
Module io compiled: Date: July 10 2013, Time: 10.46
Compiler options:  [{outdir,"/build/buildd/erlang-16.b.1-dfsg/lib/stdlib/src/../ebin"},
                    {i,"/build/buildd/erlang-16.b.1-dfsg/lib/stdlib/src/../include"},
                    {i,"/build/buildd/erlang-16.b.1-dfsg/lib/stdlib/src/../../kernel/include"},
                    warnings_as_errors,debug_info]
Object file: /usr/lib/erlang/lib/stdlib-1.19.2/ebin/io.beam
Exports: 
columns/1                     parse_erl_form/2
columns/0                     parse_erl_form/3
format/1                      parse_erl_form/4
format/2                      printable_range/0
format/3                      put_chars/2
...
parse_erl_exprs/4             setopts/2
parse_erl_exprs/3             setopts/1
parse_erl_form/1              write/1
                              write/2
ok
4

2 回答 2

5

与 Python、Lisp 等不同,Erlang 程序和 shell 会话无法访问标准库中函数的帮助文本。

我找到文档的方式是为 URL 设置一个特殊的 Firefox 书签http://www.erlang.org/doc/man/%s.html。我e为该书签指定了一个热键,这样我就可以e io在 Firefox 地址栏中键入并重定向到http://www.erlang.org/doc/man/io.html,其中包含函数的文档io模块。

或者,您可能会发现http://erldocs.com/很有用。它使您可以键入要查找的函数的名称并直接跳转到其文档。

于 2014-09-15T14:54:21.273 回答
3

截至 2020 年,在 OTP 23.0 上,现在可以使用此h功能:

摘录发布文档

shell 中的新函数用于显示 Erlang 模块、函数和类型的文档。功能是:

h/1,2,3 -- Print the documentation for a Module:Function/Arity.
ht/1,2,3 -- Print the type documentation for a Module:Type/Arity.
The embedded documentation is created as docchunks (EEP 48) when building the Erlang/OTP documentation.

例子:

2> h(lists, reverse).

  -spec reverse(List1) -> List2
                   when List1 :: [T], List2 :: [T], T :: term().

  Returns a list with the elements in List1 in
  reverse order.

  -spec reverse(List1, Tail) -> List2
                   when
                       List1 :: [T],
                       Tail :: term(),
                       List2 :: [T],
                       T :: term().

  Returns a list with the elements in List1 in
  reverse order, with tail Tail appended.

  Example:

    > lists:reverse([1, 2, 3, 4], [a, b, c]).
    [4,3,2,1,a,b,c]
ok
于 2020-10-28T15:17:43.067 回答