erlang intro

26
Learning Erlang Ivan Yatskevich Lead Software Engineer, EPAM

Upload: yatskevich

Post on 14-Dec-2014

347 views

Category:

Technology


3 download

DESCRIPTION

Presentation starts with introduction to types and Erlang's syntax. After that it demonstrates basic support for distributed programming and finally covers parallel Erlang.

TRANSCRIPT

Page 1: Erlang intro

Learning Erlang

Ivan YatskevichLead Software Engineer, EPAM

Page 2: Erlang intro
Page 3: Erlang intro

Learn at least one new language every year.

Tip 8: Invest Regularly in Your Knowledge Portfolio

Page 4: Erlang intro
Page 5: Erlang intro
Page 6: Erlang intro
Page 7: Erlang intro
Page 8: Erlang intro

Sequential Erlang

Distributed Erlang

Parallel Erlang

OTP Framework

Page 9: Erlang intro

Part I: Sequential ErlangData types, modules, functions, variables and pattern matching

Page 10: Erlang intro

Data types

• Numbers 12, 2#10, 16#FF, 2.76

• Atomsok, false, summer, ‘Wednesday’

• Bit strings and binaries<<“Are you sure?”>>, <<45, 19, 4>>

Page 11: Erlang intro

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)

Page 12: Erlang intro

(Fake) Data types

• Booleantrue, false

• String“ABC” = [65, 66, 67]

• Record (≈tuple)

Page 13: Erlang intro

Building blocks

• Modules• Functions• Clauses• Guards• MFA• BIFs

• Control structures• Case, If• Catch

Page 14: Erlang intro

Variables and Matching

Index ≠ Index + 1

Page 15: Erlang intro

{ "data": { "translations": [ { "translatedText": "Hallo Welt" } ] }}

Page 16: Erlang intro

Variables and Pattern MatchingTranslation = {data, {translations, [ {translatedText, "Hallo Welt"} ] }}.{data, {translations, [ {translatedText, Text}|Tail ] }} = Translation.

Page 17: Erlang intro

Variables and Pattern MatchingTranslation = {data, {translations, [ {translatedText, "Hallo Welt"} ] }}.

{_, {_, [{_, Text}|_]}} = Translation.

Page 18: Erlang intro

Part II: Distributed ErlangNodes, net_adm module, a lot of fun

LAN

Page 19: Erlang intro

Distributed Erlang

• Nodes$ erl –name [email protected]

• Cookies$ erl –sname nyan_cat –setcookie secret

• net_adm:pingerl> net_adm:ping([email protected]).

Page 20: Erlang intro

Part III: Parallel ErlangProcesses, Pids, message passing

Page 21: Erlang intro

Parallel Erlang

• ProcessesPid = spawn(fun() -> hi end).

• Sending messagePid ! {any_message, [“with”, list]}.

• Receiving messagereceive

Pattern1 -> action1;Pattern2 -> action2

after TimeInMs ->

action_after_timeoutend.

Page 22: Erlang intro

Parallel Erlang (cont’d)

• self()• make_ref()• System process and linking• Named processregister(name_as_atom, Pid).

Page 23: Erlang intro

Part IV: OTP FrameworkOverview

Page 24: Erlang intro

OTP Framework

http://learnyousomeerlang.com/what-is-otp

Page 26: Erlang intro

Thank you!

Q & A