Eshell V7.1 (abort with ^G) 1> Name = "Thor". "Thor" 2> Name = "Loki". ** exception error: no match of right hand side value "Loki" 3> Name. "Thor" 4> "Thor" = Name. "Thor" 5> Variables con primera letra mayúscula Todas las variables son inmutables Variables
Eshell V7.1 (abort with ^G) 1> name. name 2> ok. ok 3> error. error 4> error = error. error 5> error == error. true 6> ok == error. false 7> El nombre del atom es su mismo valor Atoms en Erlang se escriben en minúscula Atoms
Eshell V7.1 (abort with ^G) 1> [1, 2, 3]. [1,2,3] 2> []. [] 3> [one, two, three]. [one,two,three] 4> [[1,2,3],[4,5,6]]. [[1,2,3],[4,5,6]] 5> [{name, "Thor"}, {weapon, "Mjolnir"}]. [{name,"Thor"},{weapon,"Mjolnir"}] 6> El tipo de dato más importante de Erlang en cuanto a su aspecto funcional Listas
Son como Pids pero son usados para comunicación con el mundo exterior References creados con la función make_ref() sirven como identificadores únicos o cookies.
[hipe] [kernel-poll:false] [dtrace] Eshell V7.1 (abort with ^G) 1> c("thor.erl"). {ok,thor} 2> thor:smash(). I will smash you with my hammer ok 3> thor:smash("Loki"). I will smash "Loki" with my hammer ok 4> -module(thor). -export([smash/0, smash/1]). smash() -> io:format("I will smash you with my hammer~n"). smash(Target) -> io:format("I will smash ~p with my hammer~n", [ Target ]).
[kernel-poll:false] [dtrace] Eshell V7.1 (abort with ^G) 1> Name = "Thor". "Thor" 2> "Thor" = Name. "Thor" 3> Name = "Loki". ** exception error: no match of right hand side value "Loki" 4> {god, Name, Weapon} = {god, "Thor", "Mjolnir"}. {god,"Thor","Mjolnir"} 5> Name. "Thor" 6> Weapon. "Mjolnir" 7>
io:format("I will smash you with my hammer!~n"). smash(Target) -> case Target of {family, Name} -> io:format("I will not fight against ~p~n", [Name]); {enemy, Name} -> io:format("I will smash ~p with my hammer~n!", [Name]); _ -> smash() end.
[smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] Eshell V7.1 (abort with ^G) 1> c("thor.erl"). {ok,thor} 2> thor:smash({family, "Odin"}). I will not fight against "Odin" ok 3> thor:smash({enemy, "A Frost Giant"}). I will smash "A Frost Giant" with my hammer !ok 4> thor:smash("Someone else"). I will smash you with my hammer! ok 5>
[kernel-poll:false] [dtrace] Eshell V7.1 (abort with ^G) 1> c("maths.erl"). {ok,maths} 2> maths:add(1,2). 3 3> maths:add("1", "2"). ** exception error: no function clause matching maths:add("1","2") (maths.erl, line 4) 4> -module(maths). -export([add/2]). add(A, B) when is_number(A) and is_number(B) -> A + B.
Pid}. smash() -> receive {family, Name} -> io:format("I will not fight against ~p~n", [Name]); {enemy, Name} -> io:format("I will smash ~p with my hammer~n!", [Name]); _ -> io:format("I will smash you with my hamer~n!") end, smash().
[dtrace] Eshell V7.1 (abort with ^G) 1> c("thor_process.erl"). {ok,thor_process} 2> {ok, Pid} = thor_process:start(). {ok,<0.40.0>} 3> Pid ! {family, "Odin"}. I will not fight against "Odin" {family,"Odin"} 4> Pid ! {enemy, "Frost Giant"}. I will smash "Frost Giant" with my hammer !{enemy,"Frost Giant"} 5> Pid ! nothing. I will smash you with my hamer !nothing 6>