Search code examples
elixirelixir-iex

How to call an Erlang function in Elixir


What is the format to call an Erlang function in Elixir?

Specifically, how can I call the function in iex and where can I find a list of modules and functions available from Erlang.


Solution

  • First find the module and function you want to call in the Erlang OTP Reference Page Index.

    For example to call random uniform you would look in the random module and find the uniform\0 function.

    To call that in Elixir you use the format, :module.function(), e.g.,

    iex(1)> :random.uniform()
    0.7230402056221108
    

    For functions that do not take any parameters the parenthesis are optional.