模块函数的Erlang shell帮助

iyfamqjs  于 2022-12-08  发布在  Erlang
关注(0)|答案(2)|浏览(142)

I'm working in the shell and I want to view the help for the function io:format/1 .
My thought path is as follows:

  1. execute help() - I find the command m().
  2. execute m(io) - I see a list of the functions in the io module

Question: How do I drill down to find the help for the function io:format/1 from the erlang Shell?

Output from help(). :

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

Output from 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
4smxwvx5

4smxwvx51#

与Python、Lisp等不同,Erlang程序和shell会话无法访问标准库中函数的帮助文本。
查找文档的方法是为URL http://www.erlang.org/doc/man/%s.html指定一个特殊的Firefox书签,我指定了e作为该书签的热键,这样我就可以在Firefox地址栏中键入e io,并被重定向到http://www.erlang.org/doc/man/io.html,其中包含io模块中函数的文档。
或者,你可能会发现http://erldocs.com/很有用,它可以让你输入你要找的函数的名字,然后直接跳转到它的文档。

4si2a6ki

4si2a6ki2#

As of 2020, on OTP 23.0 , this now possible use h function:
Excerpt the release doc
New functions in the shell for displaying documentation for Erlang modules, functions and types. The functions are:

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.

Example:

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

相关问题