- dynamic/functional lang
- runs on Erlang VM
- Actor model - each actor is a separate process in the VM - allows concurrency
Processes are lightweight, and exchange info via messages. This isolates processes, which allows independent GCs and prevents system-wide pauses.
- Mix is the build tool
- Hex is the package manager
- IEx is the repl
- can invoke any Erlang function with no runtime cost
Basic types and operations
Functions are referred by name and arity, eg.
Strings are UTF-8 encoded
- When using binary operations,
notwhen first argument is boolean.
!the args can be of any type. (Everything except
nileval to true, just like in Ruby)
- Comparison operators:
===is more strict compared to
- Different data types can be compared. This allows sorting algorithms to not worry about data types.
=is the pattern match operator
x = 42assigns 42 to the variable x.
42 = xis ok because the operator only checks if both sides match
1 = xfails because the right side has the value 42 and left side has the value 1, and so the match fails
- Variables can only be assigned if they are on the left side
- When we try matching an unknown variable
on the right side,
Elixir thinks it is a function call to
- You can re-bind variables
^(pin operator) lets you access previously bound values
- it can be used when you need to match against a variable’s value prior to the match
Strings, binaries, char lists
- Char lists are mainly used for interfacing with old Erlang libs
- Keyword lists are similar to hashes/dictionaries in other languages
- They map to arrays of key-value tuples
- have 3 characteristics
- keys must be atoms
- keys are ordered
- duplicate keys can exist
- Key value store
Modules and functions
defmodulemacro defines a module
defdefines a function
- Functions have implicit returns
This version, using case, maps to the pattern matching version at the VM level.
Length of a list:
Run length encoding:
- Achieves concurrency by making use of actors.
- Actors are processes that can perform a specific task.
- We can send messages to an actor to ask it to do something, and it can respond by sending back a message.
- An Introduction to Elixir’s Ecto Library
- Meet Ecto, The No-Compromise Database Wrapper For Concurrent Elixir Apps
- Building Many-To-Many Associations with Embedded Schemas in Ecto and Phoenix
- Elixir lang - website
- Phoenix guides - Guides for the Phoenix web framework
- Elixir Quick Reference
- Jose Valim - How I Start
- Elixir Resources
- Elixir Style Guide
- Learning Elixir and Erlang - more resources
- Elixir - A modern approach to programming for the Erlang VM on Vimeo, Jose Valim
- Introduction to Elixir, Dave Thomas
- Think Different, Dave Thomas keynote at Elixir Conf 2014
- Études for Elixir by J. David Eisenberg