Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Created November 10, 2018 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fay-jai/3c45e841a13a2ce9404c968729519e93 to your computer and use it in GitHub Desktop.
Save fay-jai/3c45e841a13a2ce9404c968729519e93 to your computer and use it in GitHub Desktop.
list = [1, 2, 3]
# Build a list - using the cons operator on the right hand side of an expression
add_to_list = [ 4 | list ] # This results in a new list with value [4, 1, 2, 3]
# Destructuring a list - using the cons operator on the left hand side of an expression
[ head | tail ] = list
IO.puts head # head is bound to the value 1
IO.puts tail # tail is bound to the value [2, 3]
# Note there is no change to the original list - it's still bound to the value [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment