Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Erlang/OTP並行プログラミングシステムに見る情報システム技術の課題 - 第62回SEA...

Erlang/OTP並行プログラミングシステムに見る情報システム技術の課題 - 第62回SEA関西プロセス分科会

A Japanese presentation on Erlang/OTP about how the language/system is used, and what Erlang/OTP proposes to the programming communities with the strict semantics avoiding sharing among the data structures.

Kenji Rikitake

February 14, 2015
Tweet

More Decks by Kenji Rikitake

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ —ίϯϐϡʔλྺ: 41೥ —ۀքྺ: 35೥ —UNIXྺ: 30೥ —ࣾձਓྺ: 25೥ —Erlang/OTPྺ:

    7೥ —ωοτϫʔΫ԰Ͱ͢ —ηΩϡϦςΟ԰Ͱ͢ —Web԰मߦதͰ͢ Kenji Rikitake / SEA Kansai 14-FEB-2015 3
  2. ϓϩάϥϛϯάྺ —1970೥୅: 8ϏοτϚΠίϯ —1980೥୅: C, 8086, VAX —ͦͷޙ: x86, amd64,

    FreeBSD —࠷ۙ͞Θͬͨ΋ͷ: Python, Lua —ؔ਺ܕݴޠʹ͸ྼ౳ײ͕͋Γ·͢ —ΦϒδΣΫτࢦ޲͸Α͘Θ͔Γ·ͤΜ Kenji Rikitake / SEA Kansai 14-FEB-2015 4
  3. ErlangΛಈ͔͢ʹ͸ —FreeBSD: Port lang/erlang —Linux: Erlang SolutionsͷόΠφϦ —OS X: HomeBrew

    Ͱ erlang —Windows: ެࣜΠϯετʔϥ —Ұ࣍഑෍αΠτ —Erlang Solutionsͷ഑෍αΠτ Kenji Rikitake / SEA Kansai 14-FEB-2015 12
  4. ErlangΛॻ͍ͨओͳਓୡ —Bjarne Däcker: CSLabͷϦʔμʔ —Joe Armstrong: جຊ࢓༷ઃܭͱ࣮૷ —Mike Williams: CͰͷԾ૝Ϛγϯͷ࣮૷

    —Robert Virding: ϥΠϒϥϦͷ࣮૷ —Claes Wikström: ෼ࢄ؀ڥͷ࣮૷ —ͦͯ͠ݱࡏ: Ericsson OTP Team Kenji Rikitake / SEA Kansai 14-FEB-2015 23
  5. Erlangͷߏ੒ཁૉ(1) A = atom, Int = 123, Float = 1.0,

    Tuple = {A, 1.0, {x, y}}, % ༗ݶݸɼωετՄ List = [A, [1, 2], Float], % Մม௕ɼωετՄ List =:= [A | [Int, Float] ]. % head/tailԋࢉ module:func(Arg1, Arg2). % ؔ਺ݺͼग़͠ % ϚΫϩ -define(?CONST, 100). % ؔ਺֎είʔϓͷΈ X2 = X * ?CONST. % ؔ਺಺Ͱ͸?͕ͭ͘ Kenji Rikitake / SEA Kansai 14-FEB-2015 32
  6. Erlangͷߏ੒ཁૉ(2) fun module:func/2. % (2͸arity) Fun = fun(X) -> X

    * 2. % (fun͸ແ໊ؔ਺) A = <<10, 20, 30>>. % 3όΠτͷόΠφϦ <<X:12, Y:8, Z:4>> = A. % Ϗοτૢ࡞΋Մೳ [X,Y,Z] =:= [161, 65, 14]. %%% Ϧετ಺แදه: mapؔ਺ͱಉٛ [2*P || P <- [X,Y,Z]] =:= [322,130,28]. Kenji Rikitake / SEA Kansai 14-FEB-2015 33
  7. arityͱύλʔϯϚονϯά —arity: ؔ਺ͷҾ਺ͷ਺ —ύλʔϯϚονϯάͰ৚݅Λ൑ผ͢Δ test(N) when is_integer(N), N >= 1

    -> test(N, 1). test(1, A) -> A; test(N, A) -> test(N - 1, A * N); Kenji Rikitake / SEA Kansai 14-FEB-2015 34
  8. ϓϩηεؒϝοηʔδ(1) —ϓϩηε͝ͱʹड৴ശ͕͋Δ —બ୒తड৴͕Ͱ͖Δ %%% Pid: ϓϩηεID (BEAM಺Ұҙ) %%% self(): ࣗ෼ࣗ਎ͷPid

    %%% ϝοηʔδͷૹ৴ Pid ! {self(), {request, Request}}. Kenji Rikitake / SEA Kansai 14-FEB-2015 42
  9. ϓϩηεؒϝοηʔδ(2) %%% ϝοηʔδͷड৴: receiveจ %%% ؆୯ͳechoͷϧʔϓ loop() -> receive {From,

    {request, R}} -> From ! R, loop(); {From, Other} -> From ! {error, Other}, loop() end. Kenji Rikitake / SEA Kansai 14-FEB-2015 43
  10. OTPͷத਎ —ϥΠϒϥϦͱσβΠϯύλʔϯͷू·Γ —ڞ༗ετϨʔδ ets, dets —෼ࢄσʔλϕʔε Mnesia —SNMP, ASN.1, SSH,

    SSL, Ұ௨Γ͋Δ —Behaviour: αʔόσβΠϯͷύλʔϯू Kenji Rikitake / SEA Kansai 14-FEB-2015 45
  11. JavaScript (node.js)ͷྫ // var a = {first: 1, second: 2}

    // b = a // ϙΠϯλͷίϐʔͷΈ { first: 1, second: 2 } // a.second = 3 3 // b // ໊લ͕ҧͬͯ΋ཁૉ͸ڞ༗ { first: 1, second: 3 } // b == { first: 1, second: 3 } false // Կނ? Kenji Rikitake / SEA Kansai 14-FEB-2015 54
  12. ErlangͰͷྫ % A1 = {1,2,3}. {1,2,3} % B1 = A1.

    {1,2,3} % B1͸A1ͷ࣮ମͷίϐʔ % A2 = setelement(3,A1,4). {1,2,4} % B1 =:= {1,2,3}. % ൺֱԋࢉ true % ཁૉ͝ͱͷൺֱΛ͍ͯ͠Δ %%% A1, B1, A2 ͸ݸʑʹಠཱ࣮ͨ͠ମ Kenji Rikitake / SEA Kansai 14-FEB-2015 57