Elixir

Print

IO.puts "Hello world"

Variables

x = 4
x = "hello"

Data types

# Number
x = 4

# String
x = "hello world"

# Atom
x = :hello

# Tuple
{1, 2, true, 3}

# List
[1, 2, true, 3]

# Map
map = %{:name => "Peter", :age => 42}

Operators

# Arithmetic operators
rem # modulo (remainder)
div # floor division

# Logical operators
== # equal
/= # not equal
=== # type check
and # AND
or # OR
not # NOT
&& # non-strict and
|| # non-strict or
! # non-strict not

# Bitwise operators
&&& # AND
||| # OR
^^^ # XOR
~~~ # NOT
<<< # left shift
>>> # right shift

Control flow

# if-else
if a < b do
    # statement
else
    # statement
end

Functions

def my_function(x, y) do
    x + y
end

# Anonymous function
sum = fn (x, y) -> x + y end

Error handling

err = try do
    # statement
rescue
    e in RuntimeError -> e
end