$ erl Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0] [kernel-poll:false] Eshell V5.9.1 (abort with ^G) 1> A = 2 + 2. 4 2>
Integer 123456789 Floats 3.14 Atome januar, februar, true, false Tupel shape1 = {square, 4} shape2 = {circle, 5} Listen Y = ["foo", 9.5, {tuple, tuple}, [1, 2]]. X = [1, 2, 3]. "AB" = [65, 66]
1> math:fakultaet(3). 6 ok 2>
-module(math). -export([fakultaet/1]). fakultaet(0) -> 1; fakultaet(N) -> N * fakultaet(N-1).
processPacket(<<1:32/big, Rest>>) −> % process packets of type one ... ; processPacket(<<2:32/big, Rest>>) −> % process packets of type two ... ;
httpGET(<<"GET / HTTP/1.1">>) -> ...; processPacket(<< IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, ID:16, Flgs:3, FragOff:13, TTL:8, Proto:8, HdrChkSum:16, SrcIP:32, DestIP:32, RestDgram/binary >>) -> ... ;
Concurrency | Distribution | Fault-Tolerancy | Hot-Code Swapping |
The world is concurrent. Things in the world don't share data. Things communicate with messages. Things fail.
Pid = spawn(Function). Pid ! Message. Pid ! {sender, do_task, notifyAll} Calculator = spawn(calculator). Calculator ! {self(), increment, 5}.
calculator() -> receive {From, increment, Value} -> From ! Value + 1; {From, decrement, Value} -> From ! Value - 1; _ -> io:format("unknown operation") end.
3> Calculator = spawn(calculator). 4> Calculator ! {self(), increment, 5}. 6 ok
Concurrency | Distribution | Fault-Tolerancy | Hot-Code Swapping |
$ erl -name node0 -setcookie "node-group1" {process1, node1@localhost} ! your_message. {process1, node1@uni-ulm.de} ! your_message.
Concurrency | Distribution | Fault-Tolerancy | Hot-Code Swapping |
7 nines almost unachievable … but we did 9. Why is this? No shared state, plus a sophisticated error recovery model.
one_for_one, one_for_all, rest_for_one, simple_one_for_one, …
MaxR, MaxT
Concurrency | Distribution | Fault-Tolerancy | Hot-Code Swapping |
2> Service = spawn(ServiceFunction). 3> Service ! {get_price, milk}. The price of milk is: $0.99
4> c(pricing_service). {ok,pricing_service} 5> Service ! {price, milk}. The price of milk is: $1.03
Sprache | Funktional, Pattern Matching |
---|---|
Nebenläufigkeit |
Leichtgewichtige Prozesse + Asynchrones Message Passing No shared state! |
Verteilung | Erlang Nodes + Message Passing |
Michi ! Fragen.