Jordan Dimov
Jordan Dimov

Reputation: 1308

How to get help for Erlang functions from the Elixir shell

In iex, I can not get help for built-in Erlang functions, for example:

iex(1)> h :lists.reverse
:lists was not compiled with docs

Is there a way around this?

Upvotes: 8

Views: 1204

Answers (3)

I've written a module that attempts provide as much erlang documentation as possible from the unix man pages that get installed with erlang on unix systems.

https://github.com/philosophers-stone/ehelper

Example in use:

iex(3)> e :lists.reverse

                             :lists.reverse(list1)

### reverse(List1) -> List2

Types:

List1 = List2 = [T]

T = term()

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


                          :lists.reverse(list1, tail)

### reverse(List1, Tail) -> List2

Types:

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]

Upvotes: 1

Stratus3D
Stratus3D

Reputation: 4906

No. There is not.

Erlang documentation is different than Elixir documentation. As @whatyouhide said, it would mean writing an Erlang documentation parser and wiring it into h/1 in the console. While not impossible it would take some work. As far as I know no one is working on doing this.

As @Onorio Catenacci said, they do accept PR's so you (or someone else) could change this :).

Upvotes: 7

Jordan Dimov
Jordan Dimov

Reputation: 1308

As others have pointed out, there is no easy way to do this from within Elixir. However, here are some short-cuts, which might be useful for inspecting the functions available in Erlang modules from iex (even though none of this actually gives access to any documentation).

What functions are provided by a given Erlang module?

To list all functions exported by an Erlang module, use the module_info function, e.g:

Enum.each :lists.module_info(:exports), &IO.inspect/1

This prints a list of function names and their arity.

What arguments does an Erlang function accept?

To get a rough idea, you can print spec information for Erlang functions from iex using the s command:

iex(1)> s :lists.reverse
@spec reverse(list1, tail) :: list2 when List1: [t], Tail: term(), List2: [t], T: term(), list1: var, tail: var, list2: var
@spec reverse(list1) :: list2 when List1: [t], List2: [t], T: term(), list1: var, list2: var

Of course, looking up the on-line documentation is probably the best way to go about it.

Upvotes: 4

Related Questions