Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get help for Erlang functions from the Elixir shell

Tags:

erlang

elixir

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?

like image 640
Jordan Dimov Avatar asked Feb 20 '15 09:02

Jordan Dimov


People also ask

What does Elixir add to Erlang?

Adding Elixir to existing Erlang programs Elixir compiles into BEAM byte code (via Erlang Abstract Format). This means that Elixir code can be called from Erlang and vice versa, without the need to write any bindings. All Elixir modules start with the Elixir.

How to open Elixir shell?

You can launch IEx shell from the command line simply typing iex or if you want to launch a phoenix project by typing iex -S mix phx. server or typing iex -S mix while in a mix based Elixir project.

How do I start IEX?

The command to start IEx is… iex . If you press c , you will remain in IEx. If you press a , it will abort the shell and exit.

What is Elixir syntax?

The Elixir syntax shares many similarities with the Ruby syntax and is widely used to build fault-tolerant, scalable, and maintainable applications. The language provides scalability, concurrency, fault tolerance, and low latency.


2 Answers

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 :).

like image 69
Stratus3D Avatar answered Sep 28 '22 09:09

Stratus3D


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.

like image 24
Jordan Dimov Avatar answered Sep 28 '22 09:09

Jordan Dimov