Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 495
Gerry Shaw Avatar asked Feb 09 '16 04:02

Gerry Shaw


People also ask

How do you define a function in 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.

What is Defmodule Elixir?

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

What is function clause?

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 .


1 Answers

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.

like image 84
Gerry Shaw Avatar answered Sep 19 '22 12:09

Gerry Shaw