Lists

Understand how lists are used for pattern matching and variable binding.

Elixir lists can be created using square brackets containing a comma-separated set of values. It performs pattern matching. A pattern (the left side) is matched if each term in the pattern can be matched to the corresponding term in the values. A literal value in the pattern matches that exact value, and a variable in the pattern matches by taking on the corresponding value. See the below example.

Here, we have an Odd_num list containing [1, 3, 5] values. When we match it with the [x, y, 7] list, it gives us an error. But it correctly matches the [x, y, 5] list because every value of the Odd_num list matches to the ...