Erlang intro
-
Upload
yatskevich -
Category
Technology
-
view
347 -
download
3
description
Transcript of Erlang intro
Learning Erlang
Ivan YatskevichLead Software Engineer, EPAM
Learn at least one new language every year.
Tip 8: Invest Regularly in Your Knowledge Portfolio
Sequential Erlang
Distributed Erlang
Parallel Erlang
OTP Framework
Part I: Sequential ErlangData types, modules, functions, variables and pattern matching
Data types
• Numbers 12, 2#10, 16#FF, 2.76
• Atomsok, false, summer, ‘Wednesday’
• Bit strings and binaries<<“Are you sure?”>>, <<45, 19, 4>>
Data types (cont’d)
• Containers (Lists, Tuples)List = [1, true, “Erlang”]Tuple = {io, format, [“~p~n”]}
• FunctionsTripler = fun(N) -> N*3 end
• Identifiers (Refs, Pids, Ports)
(Fake) Data types
• Booleantrue, false
• String“ABC” = [65, 66, 67]
• Record (≈tuple)
Building blocks
• Modules• Functions• Clauses• Guards• MFA• BIFs
• Control structures• Case, If• Catch
Variables and Matching
Index ≠ Index + 1
{ "data": { "translations": [ { "translatedText": "Hallo Welt" } ] }}
Variables and Pattern MatchingTranslation = {data, {translations, [ {translatedText, "Hallo Welt"} ] }}.{data, {translations, [ {translatedText, Text}|Tail ] }} = Translation.
Variables and Pattern MatchingTranslation = {data, {translations, [ {translatedText, "Hallo Welt"} ] }}.
{_, {_, [{_, Text}|_]}} = Translation.
Part II: Distributed ErlangNodes, net_adm module, a lot of fun
LAN
Distributed Erlang
• Nodes$ erl –name [email protected]
• Cookies$ erl –sname nyan_cat –setcookie secret
• net_adm:pingerl> net_adm:ping([email protected]).
Part III: Parallel ErlangProcesses, Pids, message passing
Parallel Erlang
• ProcessesPid = spawn(fun() -> hi end).
• Sending messagePid ! {any_message, [“with”, list]}.
• Receiving messagereceive
Pattern1 -> action1;Pattern2 -> action2
after TimeInMs ->
action_after_timeoutend.
Parallel Erlang (cont’d)
• self()• make_ref()• System process and linking• Named processregister(name_as_atom, Pid).
Part IV: OTP FrameworkOverview
Resources
• http://www.erlang.org• http://www.tryerlang.org• http://learnyousomeerlang.com• http://www.trapexit.org/• Programming Erlang, by Joe Armstrong• Erlang Programming, by Francesco Cesarini and Simon
Thompson• Erlang and OTP in Action, by
Martin Logan, Eric Merritt, and Richard Carlsson• http://nyan.cat
Thank you!
Q & A