Skip to content

Instantly share code, notes, and snippets.

@anoxic
Last active August 29, 2015 14:02
Show Gist options
  • Save anoxic/c82f3805624d103118f7 to your computer and use it in GitHub Desktop.
Save anoxic/c82f3805624d103118f7 to your computer and use it in GitHub Desktop.
123 - Numbers
1.2 - Float
2#110 - Binary 6
{,} - Tuples
[,] - Lists (also "strings")
"ab" - A shortcut for [97,98]
atom - An atom
'atom'
Var = 1. - Setting a variable (constant).
1 = Var. - Pattern matching -- a bit like 1 == $var
[a|[a]]. - Cons -- [a,a]
[a] ++ [a] - [a,a]
[a] -- [a] - []
hd([1,2,3,4]). - 1
tl([1,2,3,4]). - [2,3,4]
[2*N || N <- [1,2,3,4]]. - [2,4,6,8] -- List comprehension - a bit like "map" here
[X+Y || X <- [1,2], Y <- [2,3]]. - [3,4,4,5] -- 1+2, 1+3, 2+2, 2+3
[X || X <- [1,2,3,4], X rem 2 == 0]. - [2,4] -- a constraint
Users = [{brian, admin},
{bob, banned},
{tim, admin}].
[X || {X, admin} <- Users]. - [brian,tim] -- Working like a "select" or constraint
http://learnyousomeerlang.com/modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment