{"id":8570,"date":"2015-12-09T09:00:18","date_gmt":"2015-12-09T00:00:18","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=8570"},"modified":"2018-11-14T16:33:47","modified_gmt":"2018-11-14T07:33:47","slug":"erlang-%e3%81%af%e3%81%98%e3%82%81%e3%81%be%e3%81%97%e3%81%9f","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2015\/12\/09\/erlang-%e3%81%af%e3%81%98%e3%82%81%e3%81%be%e3%81%97%e3%81%9f\/","title":{"rendered":"Erlang \u306f\u3058\u3081\u307e\u3057\u305f"},"content":{"rendered":"

\u7530\u4e2d\u3067\u3059\u3002\u304a\u4e45\u3057\u632f\u308a\u3067\u3059\u3002<\/p>\n

TECHSCORE Advent Calendar 2015<\/a> \u306e 9 \u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n

\u5510\u7a81\u3067\u3059\u304c\u3001Erlang \u306f\u3058\u3081\u307e\u3057\u305f\u3002<\/p>\n

Erlang \u304c\u3069\u3093\u306a\u8a00\u8a9e\u304b\u3001\u3056\u3063\u304f\u308a\u8a00\u3048\u3070\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002
\n\u30fb\u4e26\u5217\u51e6\u7406\/\u5206\u6563\u51e6\u7406\u306b\u7279\u5316\u3055\u308c\u3066\u3044\u308b
\n\u30fb\u95a2\u6570\u578b\u8a00\u8a9e\u3067\u6587\u6cd5\u304c\u7279\u6b8a<\/p>\n

\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Erlang \u306e\u59cb\u3081\u65b9\u3068\u3001\u8a00\u8a9e\u306e\u96f0\u56f2\u6c17\u304c\u308f\u304b\u308b\u3088\u3046\u306a\u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3059\u3002\u5c11\u3057\u3067\u3082 Erlang \u306b\u8208\u5473\u3092\u6301\u3063\u3066\u9802\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n

\u3068\u3053\u308d\u3067\u3001\"Erlang\" \u00a0\u306f\u300c\u30a2\u30fc\u30e9\u30f3\u30b0\u300d\u3088\u308a\u300c\u30a2\u30fc\u30e9\u30f3\u300d\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002\"ng\" \u00a0\u306f\u300c\u6709\u58f0\u8edf\u53e3\u84cb\u9f3b\u97f3\u300d\u3067\u3059\u3002\u65e5\u672c\u8a9e\u306e\u300c\u3093\u300d\u306f\u3001\u5f8c\u306b\u7d9a\u304f\u97f3\u306b\u3088\u3063\u3066\u5909\u5316\u3057\u3001\u4f8b\u3048\u3070\u300c\u307e\u3093\u304c\u300d\u300c\u3055\u3093\u307d\u300d\u300c\u304a\u3093\u3069\u300d\u306e\u300c\u3093\u300d\u306f\u5168\u3066\u9055\u3046\u97f3\u3067\u3059\u3002\u3053\u306e\u5185\u3001\u300c\u307e\u3093\u304c\u300d\u306e\u5834\u5408\u306e\u3088\u3046\u306b\u3001\u30ab\u884c\/\u30ac\u884c\u97f3\u306e\u524d\u306e\u300c\u3093\u300d\u304c\u6709\u58f0\u8edf\u53e3\u84cb\u9f3b\u97f3\u3067\u3059\u3002\u3067\u3059\u304b\u3089\u300c\u30a2\u30fc\u30e9\u30f3\u30b0\u300d\u3068\u8a00\u3046\u3064\u3082\u308a\u3067\u6700\u5f8c\u306e\u300c\u30b0\u300d\u3092\u6211\u6162\u3059\u308b\u306e\u304c\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n

\u5404\u74b0\u5883\u306e Erlang \u306f\u3053\u3053\u304b\u3089\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002
\n
https:\/\/www.erlang-solutions.com\/resources\/download.html<\/a><\/p>\n

\u7b46\u8005\u306f CentOS 7 \u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u554f\u984c\u306a\u304f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n

\r\n$ sudo rpm -Uvh http:\/\/packages.erlang-solutions.com\/erlang-solutions-1.0-1.noarch.rpm\r\n$ sudo yum install erlang\r\n<\/pre>\n

Erlang \u30b7\u30a7\u30eb\u3067\u5b9f\u884c<\/h2>\n

\u30b3\u30de\u30f3\u30c9 erl<\/strong> \u3067 Erlang \u30b7\u30a7\u30eb\u304c\u8d77\u52d5\u3057\u307e\u3059\u3002\u5bfe\u8a71\u5f0f\u306b Erlang \u304c\u5b9f\u884c\u3067\u304d\u308b\u306e\u3067\u3001\u3068\u308a\u3042\u3048\u305a\u3001\u89e6\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

$ erl\r\n \r\n1> 10 + 20.                 % \u6700\u5f8c\u306f .(\u30d4\u30ea\u30aa\u30c9) \u3067\u7d42\u308f\u308b\u3068\u3044\u3046\u6c7a\u307e\u308a\u3002\r\n30\r\n \r\n2> Foo = 1.                 % \u5909\u6570\u306f\u5927\u6587\u5b57\u3067\u59cb\u3081\u308b\u3002\r\n1\r\n \r\n3> Foo = 2.                 % \u5909\u6570\u306b\u518d\u4ee3\u5165\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u30a8\u30e9\u30fc\u3002\"\u53c2\u7167\u900f\u904e\u6027\" \u3067\u691c\u7d22\uff01\r\n** exception error: no match of right hand side value 2\r\n \r\n4> hoge.                    % \u5c0f\u6587\u5b57\u3067\u59cb\u307e\u308b\u306e\u306f\u30a2\u30c8\u30e0\u3068\u547c\u3070\u308c\u308b\u3002\u8981\u3059\u308b\u306b\u4e0d\u5909\u306e\u30ea\u30c6\u30e9\u30eb\u3002\r\nhoge\r\n \r\n5> {foo, bar, baz}.         % {}(\u6ce2\u62ec\u5f27) \u306f\u30bf\u30d7\u30eb\u3002\u8981\u7d20\u306f\u5909\u66f4\u3067\u304d\u306a\u3044\u3002\r\n{foo,bar,baz}\r\n \r\n6> [foo, bar, baz].         % [](\u89d2\u62ec\u5f27) \u306f\u30ea\u30b9\u30c8\u3002\u8981\u7d20\u3092\u8ffd\u52a0\u3057\u305f\u308a\u3001\u8272\u3005\u3067\u304d\u308b\u3002\r\n[foo,bar,baz]\r\n \r\n7> \"ABC\".                   % \u6587\u5b57\u5217\u3082\u3042\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u304c...\r\n\"ABC\"\r\n \r\n8> \"ABC\" =:= [65, 66, 67].  % \u5b9f\u306f\u305f\u3060\u306e\u6570\u5024\u306e\u30ea\u30b9\u30c8(=:= \u306f\u578b\u3068\u5024\u304c\u540c\u3058\u3068\u304d true)\u3002\r\ntrue\r\n \r\n9> q().                     % Erlang \u30b7\u30a7\u30eb\u3092\u7d42\u4e86\u3002<\/pre>\n

\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u3044\u305f\u95a2\u6570\u3092\u30b7\u30a7\u30eb\u3067\u5b9f\u884c<\/h2>\n

Erlang \u30b7\u30a7\u30eb\u3067\u306f\u95a2\u6570\u306e\u5b9a\u7fa9\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u30d5\u30a1\u30a4\u30eb\u306b\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u3001Erlang \u30b7\u30a7\u30eb\u304b\u3089\u547c\u3073\u51fa\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

\u304a\u7d04\u675f\u306e \"hello, world\" \u3067\u3059\u3002<\/p>\n

\u25cf mytest.erl<\/p>\n

-module(mytest).     % \u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u306f\u30d5\u30a1\u30a4\u30eb\u540d\u3068\u4e00\u81f4\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\r\n-export([hello\/0]).  % \u516c\u958b\u3059\u308b\u95a2\u6570\u3092\u30ea\u30b9\u30c8\u3067\u6307\u5b9a(0 \u306f\u5f15\u6570\u306e\u500b\u6570\u304c 0 \u3068\u3044\u3046\u610f\u5473)\u3002\r\n\r\nhello() ->\r\n    io:format(\"hello, world~n\").\r\n<\/pre>\n

\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092 Erlang \u30b7\u30a7\u30eb\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n

$ erl\r\n\r\n1> c(mytest).      % c \u306f compile \u306e\u7565\u3002\r\n{ok,mytest}\r\n\r\n2> mytest:hello().\r\nhello, world\r\nok<\/pre>\n

\u30b7\u30a7\u30eb\u3092\u4f7f\u308f\u305a\u76f4\u63a5\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5b9f\u884c<\/h2>\n

\u4e0a\u8a18\u306e\u65b9\u6cd5\u306f\u958b\u767a\u6642\u306b\u306f\u4fbf\u5229\u3067\u3059\u304c\u3001\u30b7\u30a7\u30eb\u306a\u3057\u3067\u5b9f\u884c\u3067\u304d\u306a\u3051\u308c\u3070\u8a71\u306b\u306a\u308a\u307e\u305b\u3093\u3088\u306d\u3002
\n\u6b21\u306f\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u76f4\u63a5\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

\u5f15\u6570\u306b\u540d\u524d\u3092\u6307\u5b9a\u3057\u3066\u3001\"Hello, \u25cb\u25cb\u25cb!\" \u3068\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n

\u25cf mytest2.erl<\/p>\n

-module(mytest2).\r\n-compile(export_all).                  % \u3044\u3061\u3044\u3061\u95a2\u6570\u540d\u3092\u6307\u5b9a\u3059\u308b\u306e\u304c\u9762\u5012\u306a\u5834\u5408\u306f\u3053\u3046\u66f8\u304f\u3002\r\n\r\nhello([Arg]) ->\r\n    io:format(\"Hello, ~s!~n\", [Arg]),\r\n    erlang:halt().                     % \u3053\u308c\u304c\u306a\u3044\u3068 Erlang VM \u304c\u7d42\u4e86\u3057\u306a\u3044\u3002\r\n<\/pre>\n

\u30b3\u30f3\u30d1\u30a4\u30eb\u306e\u30b3\u30de\u30f3\u30c9\u306f erlc<\/strong> \u3067\u3059\u3002<\/p>\n

$ erlc mytest2.erl                          # mytest2.beam (\u30d0\u30a4\u30c8\u30b3\u30fc\u30c9) \u304c\u4f5c\u6210\u3055\u308c\u308b\u3002\r\n$ erl -noshell -run mytest2 hello TECHSCORE \r\n\r\nHello, TECHSCORE!\r\n<\/pre>\n

\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u3057\u3066\u5b9f\u884c<\/h2>\n

\u7df4\u7fd2\u306e\u305f\u3081\u3001\u3061\u3087\u3063\u3068\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092 Erlang \u3067\u66f8\u3044\u3066\u307f\u305f\u3044\u306e\u306b\u3001\u3044\u3061\u3044\u3061\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u306f\u9762\u5012\u3067\u3059\u3088\u306d\u3002
\nescript<\/strong> \u3092\u4f7f\u3048\u3070\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u305b\u305a\u3001\u76f4\u63a5\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u25cf hello.erl<\/p>\n

#!\/usr\/bin\/env escript\r\n-module(hello).\r\n-compile(export_all).\r\n\r\nmain([Arg]) ->                         % \u95a2\u6570\u540d\u306f main \u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\r\n    io:format(\"Hello, ~s!~n\", [Arg]).\r\n<\/pre>\n

\u5b9f\u884c\u6a29\u9650\u3092\u4ed8\u4e0e\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059(\u52ff\u8ad6\u3001escript hello.erl \u3068\u3057\u3066\u3082\u826f\u3044\u3067\u3059)\u3002<\/p>\n

$ chmod +x hello.erl\r\n$ .\/hello.erl TECHSCORE\r\n\r\nHello, TECHSCORE!\r\n<\/pre>\n

\u3053\u308c\u306a\u3089\u3001\u6c17\u8efd\u306b Erlang \u3092\u4f7f\u3063\u3066\u307f\u3088\u3046\u3001\u3068\u3044\u3046\u6c17\u306b\u306a\u308a\u307e\u305b\u3093\u304b\uff1f<\/p>\n

\u518d\u5e30\u547c\u3073\u51fa\u3057\u3067\u53cd\u5fa9\u51e6\u7406<\/h2>\n

Erlang \u306f\u3044\u308f\u3086\u308b\u95a2\u6570\u578b\u306e\u8a00\u8a9e\u3067\u3059\u3002for \u30eb\u30fc\u30d7\u3068\u304b\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u53cd\u5fa9\u51e6\u7406\u306f\u518d\u5e30\u547c\u3073\u51fa\u3057\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n

\u30ea\u30b9\u30c8\u306e\u5148\u982d\u8981\u7d20\u3092 head\u3001\u6b8b\u308a\u306e\u90e8\u5206\u3092 tail \u3068\u547c\u3073\u307e\u3059\u3002Erlang \u306f\u3001\u30ea\u30b9\u30c8\u306e\u518d\u5e30\u51e6\u7406\u304c\u66f8\u304d\u6613\u3044\u3088\u3046\u3001head \u3068 tail \u306e\u5206\u89e3\u53ca\u3073\u7d50\u5408\u304c\u7c21\u5358\u306b\u3067\u304d\u308b\u3088\u3046\u306b\u8a2d\u8a08\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n

$ erl\r\n\r\n1> MyList = [1, 2, 3].\r\n[1,2,3]\r\n\r\n2> [Head|Tail] = MyList.  % head \u3068 tail \u306b\u5206\u89e3\u3002\r\n[1,2,3]\r\n\r\n3> Head.\r\n1\r\n\r\n4> Tail.\r\n[2,3]\r\n\r\n5> [9|MyList].            % \u5148\u982d\u306b\u8981\u7d20\u3092\u8ffd\u52a0\u3002\r\n[9,1,2,3]\r\n<\/pre>\n

\u3067\u306f\u3001\u3053\u308c\u3092\u4f7f\u3063\u3066\u3001\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u3092\u65b0\u3057\u3044\u8981\u7d20\u3067\u7f6e\u304d\u63db\u3048\u308b\u95a2\u6570<\/p>\n

replace(\u65b0\u8981\u7d20, \u65e7\u8981\u7d20, \u30ea\u30b9\u30c8)<\/p>\n

\u3092\u66f8\u3044\u3066\u307f\u307e\u3059\u3002<\/p>\n

\u25cf f_test.erl<\/p>\n

-module(f_test).\r\n-compile(export_all).\r\n\r\n% replace \u3092 3 \u3064\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u304c\u3001\u3053\u308c\u3067 1 \u3064\u306e\u5b9a\u7fa9\r\n\r\nreplace(_, _, [])                  % \u2460\u30ea\u30b9\u30c8\u304c\u7a7a\u306e\u5834\u5408\r\n    -> [];                         %  \u7a7a\u30ea\u30b9\u30c8\u3092\u8fd4\u3057\u3066\u7d42\u4e86\u3002\r\nreplace(New, Old, [Old|T])         % \u2461 head \u304c\u65e7\u8981\u7d20\u306b\u4e00\u81f4\u3059\u308b\u5834\u5408\r\n    -> [New|replace(New, Old, T)]; %  head \u3092\u65b0\u8981\u7d20\u306b\u7f6e\u304d\u63db\u3048\u3001tail \u306b\u5bfe\u3057\u3066\u518d\u5e30\u547c\u3073\u51fa\u3057\u3002\r\nreplace(New, Old, [H|T])           % \u2462\u4e0a\u8a18\u4ee5\u5916\u306e\u5834\u5408\r\n    -> [H|replace(New, Old, T)].   %  head \u306f\u305d\u306e\u307e\u307e\u3067 tail \u306b\u5bfe\u3057\u3066\u518d\u5e30\u547c\u3073\u51fa\u3057\u3002\r\n<\/pre>\n

(\u6ce8\uff1a\u3053\u306e replace \u306f\u3001\u3042\u304f\u307e\u3067\u3082\u7df4\u7fd2\u306e\u305f\u3081\u306e\u4f8b\u3067\u3059\u3002\u672c\u6c17\u3067\u4f7f\u3063\u305f\u3089 stack overflow \u306b\u306a\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\"\u672b\u5c3e\u518d\u5e30\u6700\u9069\u5316\" \u3067\u691c\u7d22\uff01)<\/p>\n

\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

$ erl\r\n\r\n1> c(f_test).\r\n{ok,f_test}.\r\n\r\n2> f_test:replace(foo, y, [x, y, z, z, y]).\r\n[x,foo,z,z,foo]\r\n<\/pre>\n

\u4e0a\u8a18 \u2461 \u306b\u304a\u3044\u3066\u306f\u3001\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b\u6bb5\u968e\u3067\u3001\u30ea\u30b9\u30c8\u3092 head \u3068 tail \u306b\u5206\u89e3\u3057\u3001head \u304c\u65e7\u8981\u7d20\u3068\u4e00\u81f4\u3059\u308b\u304b\u3069\u3046\u304b\u306e\u691c\u67fb\u307e\u3067\u3092\u884c\u3063\u3066\u3044\u308b\u308f\u3051\u3067\u3059\u3002
\n\u3053\u306e\u3088\u3046\u306a\u4ed5\u7d44\u307f\u306e\u304a\u304b\u3052\u3067\u3001\u6163\u308c\u308c\u3070\u30eb\u30fc\u30d7\u306a\u3093\u304b\u306a\u304f\u3066\u3082\u6c17\u306b\u306a\u3089\u306a\u304f\u306a\u308a\u307e\u3059(\u304d\u3063\u3068)\u3002\u95a2\u6570\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u52c9\u5f37\u306e\u305f\u3081\u306b Erlang \u3092\u9078\u629e\u3059\u308b\u3068\u3044\u3046\u306e\u3082\u60aa\u304f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n

\u3068\u306f\u3044\u3048\u3001Erlang \u3068\u8a00\u3048\u3070\u3001\u3084\u306f\u308a\u30a2\u30af\u30bf\u30fc\u30e2\u30c7\u30eb<\/strong>\u306b\u3088\u308b\u4e26\u5217\u51e6\u7406\u3067\u3057\u3087\u3046\u3002<\/p>\n

\u30a2\u30af\u30bf\u30fc\u30e2\u30c7\u30eb<\/h2>\n

\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u3092\u8d77\u52d5\u3057\u3066\u4e26\u5217\u306b\u51e6\u7406\u3092\u884c\u3046\u3068\u7af6\u5408\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u3069\u3046\u3057\u307e\u3059\u304b\uff1f<\/p>\n

1 \u3064\u306e\u89e3\u6c7a\u7b56\u306f\u3001\u30ed\u30c3\u30af\u3092\u53d6\u5f97\u3057\u3001\u30ed\u30c3\u30af\u3092\u53d6\u5f97\u3057\u305f\u30b9\u30ec\u30c3\u30c9\u4ee5\u5916\u306b\u306f\u5f85\u6a5f\u3055\u305b\u308b\u3001\u3068\u3044\u3046\u65b9\u6cd5\u3067\u3059\u3002Java \u306e synchronized \u6587\u3068\u304b\u3067\u3059\u306d\u3002<\/p>\n

\u307e\u305f\u3001\u300c\u7af6\u5408\u304c\u767a\u751f\u3059\u308b\u306e\u306f\u30b9\u30ec\u30c3\u30c9\u304c\u51e6\u7406\u306e\u9014\u4e2d\u3067\u52dd\u624b\u306b\u5272\u308a\u8fbc\u3080\u304b\u3089\u3060\u3002\u3060\u304b\u3089\u5272\u308a\u8fbc\u3080\u306e\u3084\u3081\u3088\u3046\u300d\u3068\u3044\u3046\u306e\u304c\u5225\u306e\u65b9\u6cd5\u3067\u3001\u3053\u308c\u304c\u30d5\u30a1\u30a4\u30d0\u3068\u304b\u30b3\u30eb\u30fc\u30c1\u30f3\u3068\u304b\u547c\u3070\u308c\u3066\u308b\u3084\u3064\u3067\u3059\u3002<\/p>\n

\u3053\u308c\u3089\u306b\u5bfe\u3057\u3001\u300c\u3044\u3084\u3001\u305d\u3082\u305d\u3082\u30e1\u30e2\u30ea\u3092\u5171\u6709\u3057\u306a\u3051\u308c\u3070\u7af6\u5408\u306a\u3093\u3066\u3042\u308a\u3048\u306a\u3044\u3067\u3057\u3087\u3046\u300d\u3068\u3044\u3046\u306e\u304c Erlang \u306e\u8003\u3048\u65b9\u3067\u3059\u3002\u30a2\u30af\u30bf\u30fc\u3068\u547c\u3070\u308c\u308b Erlang \u306e\u8efd\u91cf\u30d7\u30ed\u30bb\u30b9\u306f\u3001\u30d7\u30ed\u30bb\u30b9\u9593\u3067\u30e1\u30e2\u30ea\u3092\u5171\u6709\u305b\u305a\u3001\u4e92\u3044\u306b\u30e1\u30c3\u30bb\u30fc\u30b8(\u6570\u5024\u3067\u3082\u30ea\u30b9\u30c8\u3067\u3082\u4f55\u3067\u3082\u826f\u3044)\u3092\u9001\u308a\u3042\u3063\u3066\u4e26\u5217\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002\u3053\u308c\u304c\u30a2\u30af\u30bf\u30fc\u30e2\u30c7\u30eb\u3068\u547c\u3070\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u4fe1\u306f\u3001\u6f14\u7b97\u5b50 !(\u611f\u5606\u7b26) \u3092\u4f7f\u3063\u3066\u3001<\/p>\n

\u30d7\u30ed\u30bb\u30b9ID ! \u30e1\u30c3\u30bb\u30fc\u30b8<\/p>\n

\u3067\u884c\u3044\u307e\u3059<\/p>\n

\u307e\u305a ! \u306e\u52d5\u4f5c\u78ba\u8a8d\u306e\u305f\u3081\u3001Erlang \u30b7\u30a7\u30eb\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n

$ erl\r\n\r\n1> self().              % \u81ea\u8eab(\u3064\u307e\u308a Erlang \u30b7\u30a7\u30eb)\u306e\u30d7\u30ed\u30bb\u30b9ID\u3092\u8fd4\u3059\r\n<0.32.0>\r\n\r\n2> self() ! foo.        % \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\r\nfoo\r\n\r\n3> self() ! [bar, baz]. % \u3082\u3046\u4e00\u3064\u30e1\u30c3\u30bb\u30fc\u30b8(\u4eca\u5ea6\u306f\u30ea\u30b9\u30c8)\u3092\u9001\u4fe1\r\n[bar,baz]\r\n\r\n4> flush().             % \u53d7\u3051\u53d6\u3063\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u78ba\u8a8d\r\nShell got foo\r\nShell got [bar,baz]\r\nok\r\n<\/pre>\n

\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u4ed5\u69d8\u306e box \u30d7\u30ed\u30bb\u30b9\u3092\u4f5c\u6210\u3057\u3001\u3053\u306e\u30d7\u30ed\u30bb\u30b9\u3068 Erlang \u30b7\u30a7\u30eb\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u9593\u3067\u901a\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

[box \u30d7\u30ed\u30bb\u30b9\u306e\u4ed5\u69d8]
\n\u30fb\u30ea\u30b9\u30c8\u3092\u4fdd\u6301\u3059\u308b\u3002
\n\u30fb\u30e1\u30c3\u30bb\u30fc\u30b8 {\u9001\u4fe1\u5143\u30d7\u30ed\u30bb\u30b9ID, {put, \u30a2\u30a4\u30c6\u30e0}} \u3092\u53d7\u3051\u53d6\u308b\u3068\u3001\u30ea\u30b9\u30c8\u306b\u30a2\u30a4\u30c6\u30e0\u3092\u8ffd\u52a0\u3057\u3001\u8ffd\u52a0\u3057\u305f\u65e8\u306e\u6587\u5b57\u5217\u3092\u9001\u4fe1\u5143\u30d7\u30ed\u30bb\u30b9\u306b\u9001\u308b
\n\u30fb\u30e1\u30c3\u30bb\u30fc\u30b8 {\u9001\u4fe1\u5143\u30d7\u30ed\u30bb\u30b9ID, show_list} \u3092\u53d7\u3051\u53d6\u308b\u3068\u3001\u73fe\u5728\u306e\u30ea\u30b9\u30c8\u3092\u9001\u4fe1\u5143\u30d7\u30ed\u30bb\u30b9\u306b\u9001\u308b<\/p>\n

\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u53d7\u4fe1\u306f receive \u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n

\u25cf am_test.erl<\/p>\n

-module(am_test).\r\n-compile(export_all).\r\n\r\nbox(ItemList) ->\r\n    receive\r\n        {Pid, {put, Item}} ->                       % \u2460{\u30d7\u30ed\u30bb\u30b9ID, {put, \u30a2\u30a4\u30c6\u30e0}} \u306e\u5834\u5408\r\n            Pid ! lists:concat([\"You put \", Item]), %  \u9001\u4fe1\u5143\u30d7\u30ed\u30bb\u30b9\u306b\u6587\u5b57\u5217\u3092\u9001\u308a\u3001\r\n            box([Item|ItemList]);                   %  \u30ea\u30b9\u30c8\u306b\u30a2\u30a4\u30c6\u30e0\u3092\u52a0\u3048\u3066\u518d\u5e30\u547c\u3073\u51fa\u3057\u3002\r\n        {Pid, show_list} ->                         % \u2461{\u30d7\u30ed\u30bb\u30b9ID, show_list} \u306e\u5834\u5408\r\n            Pid ! ItemList,                         %  \u9001\u4fe1\u5143\u30d7\u30ed\u30bb\u30b9\u306b\u30a2\u30a4\u30c6\u30e0\u306e\u30ea\u30b9\u30c8\u3092\u9001\u308a\u3001\r\n            box(ItemList)                           %  \u30ea\u30b9\u30c8\u306f\u305d\u306e\u307e\u307e\u3067\u518d\u5e30\u547c\u3073\u51fa\u3057\u3002\r\n    end.\r\n<\/pre>\n

\u30d7\u30ed\u30bb\u30b9\u306e\u8d77\u52d5\u306f\u95a2\u6570 spawn \u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n

$ erl\r\n\r\n1> c(am_test).\r\n{ok,am_test}.\r\n\r\n2> BoxPid = spawn(am_test, box, [[dog]]).  % box \u30d7\u30ed\u30bb\u30b9\u8d77\u52d5(\u30ea\u30b9\u30c8\u306b dog \u3092\u5165\u308c\u3066\u304a\u304f)\u3002\r\n<0.40.0>\r\n\r\n3> BoxPid ! {self(), {put, cat}}.          % cat \u3092\u8ffd\u52a0\u3059\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3002\r\n{<0.32.0>,{put,cat}}\r\n\r\n4> BoxPid ! {self(), {put, rabbit}}.       % rabbit \u3092\u8ffd\u52a0\u3059\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3002\r\n{<0.32.0>,{put,rabbit}}\r\n\r\n5> BoxPid ! {self(), show_list}.           % \u30ea\u30b9\u30c8\u3092\u8fd4\u3055\u305b\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3002\r\n{<0.32.0>,show_list}\r\n\r\n6> flush().                                % box \u304b\u3089 Erlang \u30b7\u30a7\u30eb\u3078\u306e\u8fd4\u4fe1\u3092\u5168\u3066\u8868\u793a\u3002\r\nShell got \"You put cat\"\r\nShell got \"You put rabbit\"\r\nShell got [rabbit,cat,dog]\r\nok<\/pre>\n

\u7c21\u5358\u306a\u4f8b\u3067\u3059\u304c\u3001\u3061\u3083\u3093\u3068\u30d7\u30ed\u30bb\u30b9\u9593\u3067\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u53d7\u4fe1\u304c\u3067\u304d\u307e\u3057\u305f\u306d\u3002<\/p>\n

Erlang \u3092\u306f\u3058\u3081\u3066\u307f\u305f\u611f\u60f3<\/h2>\n

Erlang \u306e\u72ec\u7279\u306e\u6587\u6cd5\u306f\u3001\u8da3\u5473\u3067\u52c9\u5f37\u3059\u308b\u5206\u306b\u306f\u3068\u3066\u3082\u9762\u767d\u3044\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3067\u696d\u52d9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u66f8\u304f\u3068\u306a\u308b\u3068\u3001\u3084\u306f\u308a\u3001\u307e\u3060\u3061\u3087\u3063\u3068\u62b5\u6297\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u3067\u3082\u3001\u30a2\u30af\u30bf\u30fc\u30e2\u30c7\u30eb\u306b\u3088\u308b\u4e26\u5217\u51e6\u7406\u306f\u3001\u9811\u5f35\u3063\u3066\u7fd2\u5f97\u3059\u308b\u4fa1\u5024\u304c\u3042\u308b\u3068\u611f\u3058\u307e\u3057\u305f\u3002<\/p>\n

\u79c1\u305f\u3061\u306e Erlang \u306f\u3053\u308c\u304b\u3089\u3060\uff01<\/p>\n

(\u7b46\u8005\u306e\u6b21\u56de\u4f5c\u306b\u5fa1\u671f\u5f85\u4e0b\u3055\u3044\u3002)<\/p>\n

\u53c2\u8003\u6587\u732e<\/h2>\n

H\u00e9bert,Fred (2014)\u300e\u3059\u3054\u3044Erlang\u3086\u304b\u3044\u306b\u5b66\u307c\u3046!\u300f(\u5c71\u53e3\u80fd\u8fea\u8a33) \u30aa\u30fc\u30e0\u793e.<\/p>\n

\u3053\u306e\u672c\u306f\u3001\u3082\u3068\u3082\u3068 Web \u3067\u516c\u958b\u3055\u308c\u3066\u3044\u305f\u8a18\u4e8b\u304c\u66f8\u7c4d\u5316\u3055\u308c\u305f\u3082\u306e\u3067\u3001Web \u7248\u306f\u4eca\u3067\u3082\u7121\u6599\u3067\u95b2\u89a7\u3067\u304d\u307e\u3059\u3002
\n\u539f\u6587\uff1ahttp:\/\/learnyousomeerlang.com\/content<\/a>
\n\u7ffb\u8a33\uff1a
http:\/\/www.ymotongpoo.com\/works\/lyse-ja\/index.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u7530\u4e2d\u3067\u3059\u3002\u304a\u4e45\u3057\u632f\u308a\u3067\u3059\u3002<\/p>\n

TECHSCORE Advent Calendar 2015 \u306e 9 \u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n

\u5510\u7a81\u3067\u3059\u304c\u3001Erlang \u306f\u3058\u3081\u307e\u3057\u305f\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[215,18],"tags":[141,209],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/8570"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=8570"}],"version-history":[{"count":199,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/8570\/revisions"}],"predecessor-version":[{"id":8850,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/8570\/revisions\/8850"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=8570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=8570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=8570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}