Skip to content

Instantly share code, notes, and snippets.

@hgarcia
Created March 17, 2012 03:57
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 hgarcia/2054805 to your computer and use it in GitHub Desktop.
Save hgarcia/2054805 to your computer and use it in GitHub Desktop.
Learning Erlang
1> lists:append([[2,3,4],[5,6],[2,5,6]]).
[2,3,4,5,6,2,5,6]
2> lists:append([2,3,4],[4,5,6]).
[2,3,4,4,5,6]
3> lists:concat([an, atomic, bomb, is, big, trouble]).
"anatomicbombisbigtrouble"
4> lists:concat(["/", users, "/" , "find", "." ,"html"]).
"/users/find.html"
1> A = [1,2,3,4].
[1,2,3,4]
2> B = [5,6|A].
[5,6,1,2,3,4]
3> C = [1,2,3|[]].
[1,2,3]
1> A = [1,2,3,{name, last}].
2> A.
[1,2,3,{name,last}]
3> T = {name, last, age, {dog, charlie}}.
4> T.
{name,last,age,{dog,charlie}}
1> lists:sort([a,c,d,g,e,f]).
[a,c,d,e,f,g]
2> lists:sort([2,4,3,1,5,6,0,10,9]).
[0,1,2,3,4,5,6,9,10]
3> lists:sort([2,4,3,1,5,6,0,10,9,8,7]).
[0,1,2,3,4,5,6,7,8,9,10]
4> lists:sort([$g,$d,$a,$b,$u]).
"abdgu"
5> A = a.
6> lists:sort([2,3,a,g,6,$d,A]).
[2,3,6,100,a,a,g]
1> A = [1, 2, 3, 4, hello, world].
[1,2,3,4,hello,world]
2> B = A.
3> B.
[1,2,3,4,hello,world]
4> [C] = A.
** exception error: no match of right hand side value [1,2,3,4,hello,world]
5> [C|_] = A.
6> C.
1
7> _.
* 1: variable '_' is unbound
8> [H|Tail] = A.
9> H.
1
10> Tail.
[2,3,4,hello,world]
11> [D,E|T] = [1,2,45,67,[a]].
12> D.
1
13> E.
2
14> T.
[45,67,[a]]
6> lists:merge([[1,2,3],[4,3,5],[6,2,7]]).
[1,2,3,4,3,5,6,2,7]
7> lists:merge([[1,2,3],[3,4,5],[2,6,7]]).
[1,2,2,3,3,4,5,6,7]
8> lists:merge([2,3,4,5],[3,6,7,2,8]).
[2,3,3,4,5,6,7,2,8]
9> lists:umerge([2,3,4,5],[3,6,7,2,8]).
[2,3,4,5,6,7,2,8]
10> lists:umerge([2,3,4,5],[2,3,6,7,8]).
[2,3,4,5,6,7,8]
1> lists:reverse([4,5,6,atomic,7,bomb]).
[bomb,7,atomic,6,5,4]
1> [68,121,110,97,109,105,99].
"Dynamic"
2> Dynamic = [68,121,110,97,109,105,99].
3> Dynamic.
"Dynamic"
4> C = "Another string".
5> C.
"Another string"
6> [H|T] = C.
7> H.
65
8> T.
"nother string"
9> H = "A".
** exception error: no match of right hand side value "A"
10> H = 65.
65
11> D = "A".
12> D.
"A"
13> D = [65].
"A"
14> [$H,$e,$r,$n,$a,$n].
"Hernan"
1> A = [1,2|3].
[1,2|3]
2> [H|T] = A.
3> T.
[2|3]
4> [H2|T2] = T.
5> T2.
3
6> [H3|T3] = T2.
** exception error: no match of right hand side value 3
1> A= [1,2|[3]].
[1,2,3]
2> [H|T] = A.
3> T.
[2,3]
4> [H2|T2] = T.
5> T2.
3
6> [H3|T3] = T2.
[3]
7> T3.
[]
1> A.
* 1: variable 'A' is unbound %% Calling an unbound variable
2> A = 1. %% Bounding A to 1
3> A.
1
4> B = 'a name'. %% Bounding B to the 'a name' Atom
5> B.
'a name'
6> A = B. %% A and B don't match
** exception error: no match of right hand side value 'a name'
7> C = 'a name'. %% Bounding C to the 'a name' Atom
8> B = C. %% B and C do match
'a name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment