Elixir

Basic Types

Strings in Elixir are represented internally by contiguous sequences of bytes known as binaries.

1
2
3
4
5
6
iex> is_binary("hello")
true
iex> byte_size("hellö") # ö is not utf-8
6
iex> String.length("hellö")
5

When Elixir sees a list of printable ASCII numbers, Elixir will print that as a charlist (literally a list of characters). Charlists are quite common when interfacing with existing Erlang code.

1
2
3
4
iex> [11, 12, 13]
~c"\v\f\r"
iex> [104, 101, 108, 108, 111]
~c"hello"

Pattern Matching

1
2
{a,b,c}={:abc, "ade", 3}
[head | tail] = [1, 2, 3]

References

Licensed under CC BY-NC-SA 4.0
Get Things Done
Built with Hugo
Theme Stack designed by Jimmy