Elixir Notes: Types
Published: 2021-01-29
Intro
Elixir has a number of types similar to most programming languages.
Integer
Integers are whole numbers.
elixir
# Integers
1
42
100
9001Float
Floats are decimal place numbers.
elixir
# Floats
1.42
9000.1Boolean
Booleans are true or false values.
elixir
# Booleans
true
falseAtom
Atoms are constants where the value is the same as the name of the atom. Atoms are similar to symbols in Ruby and are defined with a colon :.
elixir
# Define an atom
:stuffNote
true, false and nil are also atoms, but they do not need to be prefixed with a colon.
String
String are defined by enclosing characters in double quotes "" and are encoded in UTF-8.
elixir
# Define a string
stuff = "stuff"
# String interpolation
"#{replace_me}"
# Multi-line string
"
Hello im a multi-line string.
"
# Heredoc strings support better formatting for multiple lines
"""
Hello
im a
string.
"""
# Sigil format can also be used
~s(I am also a string)
# The capitol sigil format is not interpolated or escaped
~S(#{i_wont_be_replaced} \n im on the same line)Links
https://elixir-lang.org/getting-started/basic-types.html
https://elixir-lang.org/crash-course.html#data-types
https://learning.oreilly.com/library/view/elixir-in-action/9781617295027/c02.xhtml