Introduction to Elixir - A Background and the Primitive Types - Part One
Repository: https://github.com/elixir-lang/elixir
What Will I Learn?
- You will learn about the BEAM and the Erlang Ecosystem and how that relates to Elixir
- You will learn about Elixir primitive types such as Numbers, Strings, Characters, Lists, Maps, Tuples and more
- You will learn how to use IEX (The Interactive Elixir Shell)
- You will learn about the Elixir compilation Pipeline
- You will learn about primitive operations and functions in Elixir
Requirements
System Requirements:
- Elixir v1.8 requires Erlang 20.0 or later
OS Support for Elixir and Phoenix:
- Mac OSx
- Unix and Linux
- Windows
- Raspberry Pi
- Docker
Required Knowledge
- Some basic Programming Knowledge
- An Elixir installation
- VsCode or any other Text Editor
Resources for Elixir and Phoenix:
- Elixir Website: https://elixir-lang.org
- Elixir Installation Instructions: https://elixir-lang.org/install.html
- Awesome Elixir Github: https://github.com/h4cc/awesome-elixir
- Phoenix Website: https://phoenixframework.org/
- Phoenix Installation Instructions: https://hexdocs.pm/phoenix/installation.html
- Elixir Documentation: https://elixir-lang.org/docs.html
- Phoenix Documentation: https://hexdocs.pm/phoenix/Phoenix.html
- LiveView Github Repository: https://github.com/phoenixframework/phoenix_live_view
Sources:
- Elixir Image: https://elixir-lang.org
Difficulty
- Beginner
Description
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.
The Basic Architecture of the BEAM and Elixir
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 Primitive Types and Operations
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
Video Tutorial
Curriculum
Related Phoenix Videos
GraphQL Series
Leave Introduction to Elixir - A Background and the Primitive Types - Part One to:
Read more #utopian-io posts
Best Posts From Tensor Programming
We have not curated any of tensor's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Tensor Programming
- Introduction to Elixir - Recursion, Tail Calls and Comprehensions - Part Five
- Introduction to Elixir - Guards and Conditional Macros - Part Four
- Introduction to Elixir - Pattern Matching and Control Flow - Part Three
- Introduction to Elixir - Functions, Built-in and Complex Types - Part Two
- Introduction to Elixir - A Background and the Primitive Types - Part One
- Phoenix Framework - Building a Chat Room with Phoenix Live View and Server Side Rendering
- A Beginners Guide to Dart - The Tooling Ecosystem - Part Nine
- A Beginners Guide to Dart - Concurrency, Asynchronous Evaluation and Parallelism in Dart - Part Eight
- Using Flare to Build Vector Graphics and Animations in Flutter
- Building a Flutter Speech to Text/Speech Recognizer Application
- A Beginners Guide to Dart - Generics, Exceptions, Factory Constructors, and Enumerated Types - Part Seven
- Dart Project - Building a Client Side Tetris Game - Part Two
- Dart Project - Building a Client Side Tetris Game - Part One
- A Beginners Guide to Dart - Scope, Iterators, Functional Programming and Collections - Part Six
- Working With gRPC in Flutter on Top of a Go Service
- A Beginners Guide to Dart - Inheritance, Abstract Classes, Interfaces, Mixins and Casting - Part Five
- A Beginners Guide to Dart - Methods, Final, Static, and Class Inheritance - Part Four
- Building a Chat app with Docker and gRPC
- A Beginners Guide to Dart - Intro to Classes and Objects - Part Three
- Building an Basic API with gRPC and Protobuf in Go