Getting Started with Elixir: Understanding Erlang, BEAM, and Your First Mix Project

Getting Started with Elixir: Understanding Erlang, BEAM, and Your First Mix Project

posted Originally published at dev.to 3 min read

Introduction

In the previous article, we covered how to set up the development environment to start working with Elixir.
Now it’s time to talk about the language itself and write our first real code.

If you are coming from languages like JavaScript, Ruby, or Python, some concepts may feel unfamiliar at first — and that’s totally normal.

Let’s start by understanding why we had to install both Elixir and Erlang.


Elixir vs Erlang

Erlang is a programming language created decades ago to solve problems related to telecommunication systems, such as reliability, concurrency, and fault tolerance.

It is extremely powerful, but its syntax is considered quite complex for many developers.

This is where Elixir comes in.

Elixir provides a modern and friendly syntax, while still running on top of the same runtime as Erlang.
In practice, your Elixir code is compiled to Erlang bytecode and executed by the same virtual machine.


What is BEAM?

BEAM stands for Bogdan/Björn’s Erlang Abstract Machine, named after its original creators.

It is the virtual machine responsible for running Erlang and Elixir code, similar to how the JVM runs Java and Kotlin.

BEAM is famous for:

  • Lightweight processes
  • Massive concurrency
  • Fault-tolerant design

This is one of the main reasons Elixir is used in systems that require high availability.


Creating Your First Project with Mix

The best way to learn a programming language is by building something.

Reading documentation and watching tutorials helps, but real learning happens when you actually write code.

In Elixir, we use Mix, the built-in build tool and project manager.

Mix is responsible for:

  • Creating projects
  • Compiling code
  • Managing dependencies
  • Running tasks and tests

Let’s create a new project.

In your terminal, run:

mix new basics

You should see an output similar to:

* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/basics.ex
* creating test
* creating test/test_helper.exs
* creating test/basics_test.exs

Now enter the project directory:

cd basics

Modules and Functions

Inside the lib directory, you will find the file basics.ex with the following content:

defmodule Basics do
end

In Elixir, almost all code lives inside modules.

A module is simply a collection of functions.

Let’s add our first function:

defmodule Basics do
  def create_list do
    [1, 2, 3, "little indians"]
  end
end

We use def to define a function inside the Basics module.


Running the Project with IEx

To run and test our code, we use IEx (Interactive Elixir Shell).

It works like Python’s REPL or Ruby’s IRB, allowing you to run Elixir code interactively.

From the project directory, run:

iex -S mix

Now test the function:

Basics.create_list()

You should get:

[1, 2, 3, "little indians"]

Notice that the last expression is automatically returned.
This is called implicit return, which is common in functional programming.


Object-Oriented vs Functional Programming

In object-oriented languages, you usually create objects and call methods on them.

In functional programming, functions return values directly without relying on object instances.

In Elixir:

  • There are no classes
  • Modules are not objects
  • Functions return data

A module is just a namespace for functions, nothing more.


Understanding Arity

In Elixir, functions are identified not only by their name, but also by the number of arguments they receive.

This is called arity.

Let’s create a new function:

def shuffle(list) do
end

Now recompile inside IEx:

recompile

And try calling:

Basics.shuffle()

You will see an error similar to:

function Basics.shuffle/0 is undefined. Did you mean shuffle/1?

That means the function expects one argument.

Example:

defmodule Basics do
  def hello(), do: "Hello World"            # hello/0
  def hello(name), do: "Hello, #{name}"    # hello/1
  def hello(a, b), do: "#{a} and #{b}"      # hello/2
end

These are considered different functions because of their arity.

Arity is written as:

function_name/number_of_arguments

It becomes very important later when working with pattern matching and function clauses.

More about functions and arity:
https://elixirschool.com/en/lessons/basics/functions/


Conclusion

In this article we covered:

  • The relationship between Elixir and Erlang
  • What BEAM is and why it matters
  • How to create projects with Mix
  • How modules and functions work
  • What function arity means

In the next article, we’ll continue improving this project and exploring more Elixir features.

See you soon!

1 Comment

0 votes

More Posts

Elixir Setup Guide: Installing Erlang, Elixir, and Livebook with ASDF

Igor Giamoniano - Coisa de Dev - Jan 12

Local-First: The Browser as the Vault

Pocket Portfolioverified - Apr 20

Dental Cone Beam Computed Tomography: Your Complete Guide to 3D Dental Imaging

Huifer - Feb 5

Your Tech Stack Isn’t Your Ceiling. Your Story Is

Karol Modelskiverified - Apr 9

Architecting a Local-First Hybrid RAG for Finance

Pocket Portfolioverified - Feb 25
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!