updated: 28th of January 2021
published: 26th of January 2021
Define a variable in Elixir with the equals = operator.
# Valid variable assignments
stuff = "stuff"
valid_variable = "Hi im valid"
_me_too = "Im also valid"
me_good? = true
# Valid variable assignments but discouraged
dontDoThis = "Hi from Java"
# Invalid variable assignments
BooHoo = "Im invalid and will cause an error" # -> ** (MatchError) no match of right hand side value: "Im invalid and will cause an error"
# To perform a pattern match rather than an assignment
# Prefix the left hand side with the ^ operator.
^stuff = "things" # -> ** (MatchError) no match of right hand side value: "things"
https://elixir-lang.org/crash-course.html#variable-names
https://learning.oreilly.com/library/view/elixir-in-action/9781617295027/c02.xhtml