$ iex
iex> 1 # integer
iex> 0x1F # integer
iex> 1.0 # float
iex> true # boolean
iex> :atom # atom (symbol)
iex> "elixir" # string (binary)
iex> 'elixir' # charlist (erlang string)
iex> [1, 2, 3] # list
iex> {1, 2, 3} # tuple
iex> %{a: 1, b: 2, c: 3} # map
iex> 1 + 2
3
iex> 5 * 5
25
iex> 10 / 2
5.0
iex> div(10, 2) # int div
5
iex> div 10, 2
5
iex> rem 10, 3 # modulo
1
iex> 0b1011
11
iex> 0o777
511
iex> 0x1F
31
iex> 1.0
1.0
iex> 1.0e-10
1.0e-10
iex> round(3.58)
4
iex> trunc(3.58)
3
iex> "hellö"
"hellö"
iex> "hellö #{:world}"
"hellö world"
iex> byte_size("hellö")
6
iex> String.length("hellö")
5
iex> String.upcase("hellö")
"HELLÖ"
iex> [1, 2, true, 3]
[1, 2, true, 3]
iex> length [1, 2, 3]
3
iex> [1, 2, 3] ++ [4, 5, 6]
[1, 2, 3, 4, 5, 6]
iex> [1, true, 2, false, 3, true] -- [true, false]
[1, 2, 3, true]
iex> [11, 12, 13]
'\v\f\r'
iex> [104, 101, 108, 108, 111]
'hello'
iex> tuple = {:ok, "hello"}
{:ok, "hello"}
iex> put_elem(tuple, 1, "world")
{:ok, "world"}
iex> tuple
{:ok, "hello"}
iex> [a: 1, b: 2] # keyword list
[a: 1, b: 2]
iex> [{:a, 1}, {:b, 2}] # same as above
[a: 1, b: 2]
iex> %{a: 1, b: 2, c: 3}
%{a: 1, b: 2, c: 3}
iex> %{"a" => 1, :b => 2, {:user, 3} => 3}
%{:b => 2, {:user, 3} => 3, "a" => 1}
defmodule Calc do
def add(x, y) do
x + y
end
def mult(x, y) do
do_mult(x, y)
end
defp do_mult(x, 1), do: x
defp do_mult(x, y) when y > 1 do
do_mult(x, y-1) + x
end
end
OMG
|> WTF
|> BBQ
"abcdefg"
123
%{"OMG": "wtf"}
defmodule Foo do
@moduledoc """
OMG WTF
"""
def foo(%{omg: wtf}) do
wtf
end
end