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.
A function is uniquely defined by the module name, function name, and arity. That is, two functions with the same name and in the same module, but with different arities are two different functions. A function named f in the module m and with arity N is often denoted as m:f/N.
In order to create our own modules in Elixir, we use the defmodule macro. The first letter of the module must be in uppercase. We use the def macro to define functions in that module. The first letter of every function must be in lowercase (or underscore):
A function declaration is a sequence of function clauses separated by semicolons, and terminated by period (.). A function clause consists of a clause head and a clause body, separated by -> . A clause head consists of the function name, an argument list, and an optional guard sequence beginning with the keyword when .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With