Wichtige Module
| Modul | Zweck |
|---|---|
lists | Listenfunktionen |
maps | Map-Funktionen |
string, binary, re | Text, Binaries, reguläre Ausdrücke |
io, io_lib | Ein- und Ausgabe |
file, filename | Dateien |
ets, dets, mnesia | Tabellen und Datenbank |
gen_server, supervisor | OTP-Behaviours |
timer, erlang | Zeit, Systemfunktionen |
math, rand | Mathematik, Zufall |
main(_) ->
io:format("~p~n", [erlang:system_info(otp_release) >= "20"]),
io:format("~p~n", [is_pid(self())]),
io:format("~p~n", [is_function(fun(X) -> X end)]),
io:format("~p~n", [erlang:abs(-7)]),
io:format("~p~n", [element(1, {a, b})]),
io:format("~p~n", [is_list("abc")]),
io:format("~p~n", [atom_to_list(hallo)]),
io:format("~p~n", [list_to_atom("welt")]),
io:format("~p~n", [length([])]),
io:format("~p~n", [min(3, 9)]),
io:format("~p~n", [rand:uniform(6) >= 1]),
io:format("~p~n", [is_binary(<<1>>)]),
io:format("~p~n", [erlang:process_info(self(), message_queue_len)]),
io:format("~p~n", [timer:tc(fun() -> ok end) =/= error]),
io:format("~p~n", [calendar:is_leap_year(2024)]),
io:format("~p~n", [calendar:day_of_the_week(2024, 3, 15)]),
io:format("~p~n", [filename:extension("a/b/c.txt")]),
io:format("~p~n", [filename:join(["a", "b", "c.txt"])]),
io:format("~p~n", [file:read_file("/nicht/da")]).Ausgabe
true
true
true
7
a
true
"hallo"
welt
0
3
true
true
{message_queue_len,0}
true
true
5
".txt"
"a/b/c.txt"
{error,enoent}Typische Fehler
main(_) ->
X = 1,
X = 2.Fehlermeldung
no match of right hand side value 2
main(_) ->
unbekannt:funktion().Fehlermeldung
undef
Weiterführende Quellen
- erlang.org/doc: Dokumentation und Reference Manual
- „Learn You Some Erlang for Great Good!“ (learnyousomeerlang.com, kostenlos)
- „Erlang and OTP in Action“ und „Designing for Scalability with Erlang/OTP“
- adoptingerlang.org: Praxis mit rebar3 und Releases
Merke
- Erlang: funktional, nebenläufig, fehlertolerant
- Prozesse, Nachrichten und Supervisor sind das Kernrezept
- BEAM, OTP und rebar3 bilden die Werkzeugkette
Aufgabe
Baue einen kleinen Chat-Server mit einem Prozess pro Client.