In this Video Tutorial, we start a new series on the Elixir language. We talk about what the Elixir language is and how it came about. We discuss the technical aspects of the Elixir language and how it relates to the BEAM (Bogdan's Erlang Abstract Machine). We look at how Elixir is compiled into Erlang and we talk about the advantages that the BEAM gives us. We also look at the primitive types that exist in Elixir and how they work with simple operators.
In 1986, the Swedish telecom giant Ericsson developed the Erlang language and the BEAM. This system was devised at the core of the OTP or Open Telecom Platform and used primarily to automate Telephone switchboards. In 2011, an alternative syntax for the BEAM was released in the form of Elixir. Elixir was designed as a means to harness the power of the BEAM and the OTP system and make these systems more accessible to developers.
Above is an image of a few flow charts showing how Elixir compiles to the BEAM and how the BEAM works across multiple CPU cores. Elixir is an alternative syntax on the BEAM and so its able to completely harness the system. Elixir follows a few separate steps towards compilation than Erlang but these steps provide elixir with some nice features such as macros and full Erlang inter-opt. You could write a full Erlang program inside of an Elixir program and have it compile without issue.
On the Beam everything is a process and these processes are strongly isolated. The Processes communicate with one another through the use of message passing which gives rise to the Actor Model. Each process is run on top of a set of schedulers which decide how these processes are distributed across each of the CPU Cores. The Beam itself only runs on a single thread but the schedulers are able to distribute the CPU threads of operation to the processes allowing the application to fully use a Multicore CPU.
Elixir supports all of the primitive types from the Erlang system and it adds to these types to make them more accessible. There are the number types, integers and floats which also use simple operations. Elixir also makes use of Atoms which are alphanumeric constants that refer to themselves. Elixir also has a large amount of collection types; this includes Tuples, Singly linked Lists, Maps, Strings, Binaries, Bitstrings and CharLists. All of these collection types have their own pros and cons and are useful in the ecosystem.
Above we have examples of these elixir primitives. Each of the primitives contains a set of functions and operations that can be applied to them to execute commands. All values in Elixir are Immutable and these primitives are very efficient as immutable data in memory. The collection types also are immutable and when you change a portion of a collection, the parts that are unchanged still refer to the old collection. This means that pieces of memory can be reused in response to demand. Some of the types such as Strings and Charlists are actually built on top of some of the other types like Binaries and Bitstrings. There are also multiple ways to define these primitives thanks to the macro system in Elixir.
Full Github Source Code can be found here: https://github.com/tensor-programming/intro-to-elixir