Created
November 10, 2018 21:13
-
-
Save fay-jai/3c45e841a13a2ce9404c968729519e93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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