An Erlang Foundation


Elixir is a compiled language that runs on the Erlang Virtual Machine. It compiles down to byte code with the .beam extension.

From the start, Erlang was built on three principles: fault tolerance, concurrency and distribution. These principles were defined by the projected use case for this language, the telecommunication industry. Another critical assessment during the long life of Erlang was memory management. Erlang defines lightweight processes to perform work in parallel. These processes are completely unique and unrelated to the processes associated with the operating system. They are inexpensive processes created by the virtual machine that contain their own independent heap and memory. Erlang implements a message system to communicate between processes, avoiding the need to share memory.

Elixir is an answer to Erlang’s syntax and lack of modern tooling. The creator, Jose Valim, was a core contributor to Ruby on Rails and wanted to bring some of the "Rails experience" to the Erlang ecosystem. The package manager Hex and the build tool Mix provide a unified experience for various developing tasks like scaffolding, testing, compiling and deploying.

Since Elixir uses the Erlang system, code and tools can be used interchangeably. Elixir code compiles to the same bytecode that is used by the Erlang virtual machine and runtime called BEAM (Bodgan’s Erlang Abstract Machine). This means that despite being a relatively new language, Elixir can leverage the experience gained over the last 30 years, especially with consideration to OTP (Open Telecom Platform).

Erlang Interoperability

Erlang modules can be accessed directly within Elixir code. This interoperability makes Erlang's extensive standard library available within Elixir at no additional cost. Accessing Erlang modules can be done by prepending a colon ( : ) to the module name, as in :timer or :random, followed by a function call via dot notation. Reviewing Erlang's documentation of the Timer module, we find the sleep/1 function. Remember, the number after the function name is the function's arity, the expected number of arguments. In this case, :timer.sleep/1, the single argument expected is the number of milliseconds the function should "sleep" (delay execution). Here's a simple example in iex:

iex(1)> IO.puts "Hello" ; :timer.sleep 5000 ; IO.puts "World!"
Hello
# 5 second delay #
World
:ok

In the example above, semicolons allow the three statements to be written on a single line. I access the sleep function within the :timer module by using the syntax, :module.function.

results matching ""

    No results matching ""