Habréã®Erlang / ErlangãèŠããšããç§ã¯ãã®ãããã¯ãå°ãã«ããŒãããŠããããšã«æ°ã¥ããŸãããèšèªã®ãããã¯ã«é¢ããããã€ãã®æ¬åœã«è¯ãèšäºãããããŸããïŒããšãã°ã alex_blankã«ãã£ãŠç¿»èš³ãããèšèªã®äœæè ããã®çŽ æŽãããèšäºããããŸãã ãã®ãããç§ã¯æåã«èšèªèªäœãšããã®èšèªãšåŸæ¥ã®èšèªãšã®éãã«ã€ããŠèª¬æããŸãã
ä»®æ³ãã·ã³ãšããŒã
ãŸããErlangã§æžãããããã°ã©ã ã¯ä»®æ³ãã·ã³å ã§ã®ã¿å®è¡ãããããšãæ確ã«ããããšæããŸããä»®æ³ãã·ã³ã¯Erlangã§ã¯ããŒããšåŒã°ããŸãã ã»ãšãã©ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ïŒWindowsãLinuxãMac OSãFreeBSDãErlangã¯iPhoneã§ãèµ·åããããšèªã¿ãŸããïŒã«ã¯ãä»®æ³ãã·ã³ïŒãŸãã¯Erlang / OTP ïŒã®ããŒãžã§ã³ããããŸãã Cã®ãœãŒã¹ã³ãŒãã¯ãªãŒãã³ã§ããããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ã³ã³ãã€ã«ã¯åé¡ã«ãªããŸããã åãã³ã³ãã¥ãŒã¿ãŒäžã§è€æ°ã®ããŒããå®è¡ã§ããŸãããããã¯ã»ãšãã©å¿ èŠãããŸããã ãããã¯ãŒã¯äžã®ä»ã®ã³ã³ãã¥ãŒã¿ãŒäžã®ä»ã®ããŒããšéä¿¡ããã«ã¯ãåããŒãã«åºæã®ååãå¿ èŠã§ãã ãããã¯ãŒã¯äžã®ä»ã®ããŒããšã®çžäºäœçšãäºæ³ãããªãå ŽåãããŒãã«ååããªãå¯èœæ§ããããŸãã ããŒãåã®åœ¢åŒã¯æ¬¡ã®ãšããã§ãããåå@ IPãŸãã¯ã³ã³ãã¥ãŒã¿ãŒåãã ããšãã°ãããŒã«ã«ãããã¯ãŒã¯ã®äŸïŒtest@192.168.0.101ã ãã€ãã£ãããã»ããµã³ãŒãã«ã¯Erlangããã°ã©ã ã®ã³ã³ãã€ã©ã§ããHiPEïŒ é«æ§èœãã€ãã£ãã³ãŒãã³ã³ãã€ã© ïŒããããŸãã Erlang / OTPã®äžéšã§ãã HiPEã¯ããã€ããªããŒã¿ïŒã»ãŒ10åïŒãšæµ®åå°æ°ç¹æŒç®ïŒæµ®åå°æ°ç¹æŒç®ïŒã§äœæ¥ããå Žåã«æ倧ã®å éãæäŸããŸããä»ã®å Žåãé床ã®å¢å ã¯ãããã§ãã
äžåºŠã ãå€ãå²ãåœãŠãããšãã§ããå€æ°
ä»ã®èšèªã§ã¯å©çšã§ããªãErlangã®ã¯ãŒã«ãªç¹ãšãåŸæ¥ã®ããã°ã©ãã³ã°èšèªïŒCãDelphiãBasicãªã©ïŒã®ããã°ã©ããŒã«ãšã£ãŠããã»ã©é ãçãã®ã¯äœã§ããïŒ
Erlangã«ã¯å€æ°ããããŸãããå€ãå²ãåœãŠãåŸã¯å€æŽã§ããŸããã ãããã®å€æ°ã¯äœã§ããïŒ ã¯ãããããã¯ãŸã å€æ°ã§ããããã2ã€ã®ç¶æ ããããŸãïŒç¡é¢ä¿ïŒå€ããŸã å²ãåœãŠãããŠããªãïŒãšãã€ã³ãïŒå€ãå²ãåœãŠãããŠããïŒã ãããŠãããã¯å¶ç¶ã§ã¯ãªãèšèªã§è¡ãããŸãã ãŸããä»®æ³ãã·ã³ã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãå€§å¹ ã«ç°¡çŽ åãããŸãïŒãã€ã³ã¿ãŒã«åŸãå¿ èŠã¯ãããŸããïŒã 第äºã«ãããã»ã¹éã§äœãå ±æããªããããããããã»ã¹ãå¥ã®ããã»ã¹ã®ããŒã¿ãæå·ããããšãæããããšãªããå€ãã®å¥åã®ããã»ã¹ã«åå²ãããã¢ã«ãŽãªãºã ãç°¡åã«äœæã§ããŸãã
ååž°
ããããå€æ°ã®å€ãå€æŽã§ããªãå Žåãããšãã°ãã©ã®ããã«ã«ãŒããå®è£ ã§ããŸããïŒ ååž°ïŒ Erlangã§æ°å€Xã®Nä¹ãè¡ãæãç°¡åãªäŸã次ã«ç€ºããŸãã
raising(1, _X, Result) ->
Result;
raising(N, X, Result) ->
raising(N-1, X, Result*X).
ã³ã³ãã¯ãã§çŸããã ããšãã°ãraisingïŒ3ã10ã10ïŒã¯1000ãè¿ããŸãããšããã§ãraisingïŒ2000ã2ã2ïŒãšæžãããšãã§ããŸãã éåžžã«å€§ããªæ°ã衚瀺ãããŸãããèšç®ã¯åé¡ãªãå®äºããŸãã Erlangã®å¥ã®èå³æ·±ãããããã£ã¯ããã«é ãããŠããŸããå€æ°ã®å³å¯ãªåä»ãã¯ãããŸããããããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãã
ååž°ã¯æªãããšããªãã¯èšããŸãïŒ ãã ããErlangã§ã¯ãªããååž°ãæ«å°Ÿååž°ãšããŠèšè¿°ãããŠããå Žåãã€ãŸããé¢æ°ãããèªäœãåŒã³åºããåŸã«äœãå®è¡ãããªãå Žåã§ãã äžèšã®äŸã¯ãæ«å°Ÿååž°ã®åãªãäŸã§ããïŒN-1ãXãAmount * XïŒãäžããåŸã¯äœããããŸããã ãããŠãä»®æ³ãã·ã³ã¯ã¹ã¿ãã¯äžã®é¢æ°åŒã³åºããèšæ¶ããå¿ èŠããããŸããã 圌女ã¯ããã«ããããå¿ããã®ã§ãããã¯éåžžã«è¿ éã«æ©èœãããã¹ãã®æ°ã«å¶éã¯ãããŸããã
ããã»ã¹
ããŒãã§å®è¡ããããã®ã¯ãã¹ãŠãåå¥ã®ããã»ã¹ããŸãã¯å¥ã®ããã»ã¹ã®äžéšã§ãã ããã»ã¹ã¯ä»ã®ããã»ã¹ãçæããäºãã«ãã©ããŒã§ããŸãã åããã»ã¹ã«ã¯ãPIDãšåŒã°ããç¬èªã®çªå·ããããŸãã ããã«ãããã¯éåžžã«éèŠã§ãããPIDã¯1ã€ã®ããŒãã ãã§ãªãããããã¯ãŒã¯äžã®ãã¹ãŠã®ããŒãã§äžæã§ãïŒ ããã»ã¹ã¯ãselfïŒïŒé¢æ°ãåŒã³åºãããšã«ãããèªèº«ã®PIDãèªèã§ããŸãã é¢æ°ãå¥ã®ããã»ã¹ãšããŠå®è¡ããäŸã次ã«ç€ºããŸãã
Pid = spawn(?MODULE, raising, [3, 10, 10]).
PIDã«å ããŠãä»»æã®ããã»ã¹ã«äžæã®ååãä»ããããšãã§ããŸãã
register(unique_name, Pid).
ãã®åŸãPIDãç¥ããªããŠãããããã¯ãŒã¯äžã®ä»»æã®ããŒãããååã§ãã®ãããªããã»ã¹ã«ã¢ã¯ã»ã¹ãããšäŸ¿å©ã§ãã
ç¹°ãè¿ããŸããããã¹ãŠããã£ããåäœãããšããçåãçãããããããŸããã ãŸããããïŒ ãŸããErlangã®ããã»ã¹ã¯ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ããã»ã¹ãšã¯é¢ä¿ãããŸããïŒErlangã«ã¯ç¬èªã®ããã»ã¹ã¹ã±ãžã¥ãŒã©ããããŸãïŒã å žåçãªäžåãã·ã³ã§ã¯ãåçŽãªããã»ã¹ã¯æ¯ç§çŽ350,000ããå§ãŸããŸãã ããã»ã¹ã¯å€ãã®ã¡ã¢ãªãæ¶è²»ããã®ã§ããããïŒ å€§ããããšã¯ãããŸããïŒ4kbããæãåçŽãªããã»ã¹ãŸã§ã ããã«ãããã»ã¹ã¯èµ·åçŽåŸã«äŒæ¢ç¶æ ã«ãªãå¯èœæ§ããããŸãããã®åŸãããã»ã¹ããšã«äžè¬çã«ã¡ã¢ãªãµã€ãºã1kbã«æžããããšãã§ããŸãã
çžäºã«å¯Ÿè©±ããããã«ãããã»ã¹ã¯çžäºã«ã¡ãã»ãŒãžãéä¿¡ã§ããŸãã
Pid ! {self(), hi}.
ããã«ãåãããŒãã®ããã»ã¹ã«ã¡ãã»ãŒãžãéä¿¡ãããããããã¯ãŒã¯äžã®å¥ã®ã³ã³ãã¥ãŒã¿ãŒã«ã¡ãã»ãŒãžãéä¿¡ãããã«ãã£ãŠæ§æã¯å€ãããŸããïŒ
ãã®ãããããã»ã¹ã«ãã£ãŠã¡ãã»ãŒãžãåä¿¡ãããŸãã
receive
{Pid, hi} ->
Pid ! hello;
OtherMessage ->
Io:format(âI received some strange message: ~p~nâ, [OtherMessage])
end.
åæããŠãã¡ãã»ãŒãžãéåä¿¡ããããã®ã³ãŒãã¯éåžžã«ã³ã³ãã¯ãã§ãã äžèšã®äŸã§ã¯ãããã»ã¹ã¯ã¡ãã»ãŒãžãåä¿¡ãããŸã§æ°žä¹ ã«åŸ æ©ããŸãã ããã¯ããafter Nããããã¯ãåä¿¡æ§æã«è¿œå ããããšã§åé¿ã§ããŸããNã¯ãã¡ãã»ãŒãžã®åä¿¡ãåŸ æ©ããããªç§æ°ã§ãã
äž»ãªæ©èœ
Erlangã®æŠèŠïŒ
- ããã»ã¹ã®äœæãšç Žæ£ã¯éåžžã«é«éã§ãã
- ããã»ã¹éã®ã¡ãã»ãŒãžã³ã°ã¯ââéåžžã«é«éã§ãã
- å€ãã®ããã»ã¹ãéå§ã§ããŸãïŒå®éã«ã¯ã1ã€ã®ããŒãã§2000äžããã»ã¹ãçè«äžã¯æ倧1å2000äžããã»ã¹ãèµ·åããŸããïŒã
- ããã»ã¹ã¯äœãå ±æãããå®å šã«ç¬ç«ããŠããŸãã
- ããã»ã¹éã®å¯Ÿè©±ã®äž»ãªæ¹æ³ã¯æ¬¡ã®ãšããã§ããã¡ãã»ãŒãžãéä¿¡ããŸãã
ãŸããErlangã§100äžã®åææ¥ç¶ãæäŸããã³ã¡ãããµãŒããŒã®äœæã«ã€ããŠèª¬æããè¯ãèšäºã¯æ¬¡ã®ãšããã§ããhttp ïŒ //www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3/ ïŒèšäº3ã€ã®éšåã§æ§æãããŸãïŒ ã Erlangã§ã¯ããã®åé¡ã¯éåžžã«ç°¡åã«è§£æ±ºãããŸãã
çš®é¡
Erlangã®å€æ°ã«ã¯ãä»»æã®åã®å€ãå²ãåœãŠãããšãã§ããŸãã ãã ããçµã¿èŸŒã¿é¢æ°ïŒis_integerãis_binaryãªã©ïŒã䜿çšããŠãç¹å®ã®å€æ°ã«å«ãŸããå€ã®ã¿ã€ãã確èªããããšãã§ããŸãã éåžžãèšèªã«å³å¯ãªåä»ãããªãããšã¯æ¬ ç¹ãšèŠãªãããŸãããå®éã«ã¯ããã®å©ç¹ãããã°ã©ã ã®æè»æ§ãå€§å¹ ã«é«ããããšãå€ããšç¢ºä¿¡ããŸããã ããã«ãåã«é¢ããæœåšçãªãšã©ãŒãåé¿ããããã«ãErlangã«ã¯ããã®ãããªãšã©ãŒãæ€åºããéçã¢ãã©ã€ã¶ãŒDialyzerãå«ãŸããŠããŸãã
ç£ç£è
ããã§ã¯ãErlang / OTPéçºç°å¢ã®éåžžã«èå³æ·±ãç¹æ§ã«ç§»ããŸãããã Erlangã§æžãããããã°ã©ã ã¯éåžžãåã«ä¿¡é Œã§ããã ãã§ãªããéåžžã«ä¿¡é Œã§ãããšèããããŠããŸãã ããã¯ã©ã®ããã«æ©èœããŸããïŒ ãã¹ãŠãã·ã³ãã«ã§ãã Erlangã§èšè¿°ãããã¢ããªã±ãŒã·ã§ã³å šäœã¯ãç°¡åã«èšãã°ãã¹ãŒããŒãã€ã¶ãŒïŒã¹ãŒããŒãã€ã¶ãŒã¯åããã»ã¹ãç£èŠããç¹å¥ãªããã»ã¹ïŒãšã¡ã€ã³ã®äœæ¥ãå®è¡ããã¯ãŒã¯ããã»ã¹ã«åããããŸãã ãã®è©³çŽ°ã«ã€ããŠã¯ã OTPèšèšååãåç §ããŠãã ãã ã Erlangã«ã¯ããã®ãããªã°ãããæŠå¿µãããããŸãããããã»ã¹ãæ»ãªãããã ãããŠãæ¬åœã«ããã§ãã ããã»ã¹ãã¹ãŒããŒãã€ã¶ãŒã®ç®¡çäžã«ããå Žåããã®ããã»ã¹ãèœäžããå Žåãã¹ãŒããŒãã€ã¶ãŒã«ãã£ãŠåèµ·åãããŸãã äžè¬ã«ãã¹ãŒããŒãã€ã¶ãŒã¯ãåããã»ã¹ãã¯ã©ãã·ã¥ããå Žåã®åäœãæè»ã«æ§æã§ããŸãã ããšãã°ããã®ãããªç¶æ³ã§ã¯ã圌ã¯ãã¹ãŠã®åããã»ã¹ãåæ¢ããŠãæåããããçŽãããšãã§ããŸãã ããã¯ãè£å©ããã»ã¹ãäœããã®åœ¢ã§äºãã«äŸåããŠãããäžæ¹ã®ããã»ã¹ãä»ã®ããã»ã¹ã®æ©èœäžå šã«ã€ãªããå¯èœæ§ãããå Žåã«å¿ èŠã§ãã
ãããã£ãŠãOTPã®ååã«åºã¥ããŠæ§ç¯ãããããã°ã©ã ã¯ãããã»ã¹ã®ããªãŒã®ããã«èŠããŸãã
OTPèšèšååããåãããå³ã
ã¹ãŒããŒãã€ã¶ãŒã¯èšç®ãè¡ããã芳å¯ã®ã¿ãè¡ãããã転åã®ç¢ºçã¯ãŒãã«ãªãåŸåããããŸãã ãã¡ãããããšãã°ã¡ã¢ãªäžè¶³ãåå ã§ããŒãå šäœãèœã¡ãå¯èœæ§ããããŸããã解決çããããŸããããŒããç£èŠããäžå®æéåŸã«åèµ·åãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ç¹å¥ãªããã»ã¹ãéå§ã§ããŸãã å¥ã®ãªãã·ã§ã³ããããŸãïŒ åæ£ã¢ããªã±ãŒã·ã§ã³ -ãããã¯ãè€æ°ã®ããŒãã§å®è¡ã§ããã¢ããªã±ãŒã·ã§ã³ã§ãã ããã«ãããæç¹ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã¯1ã€ã®ããŒãã§ã®ã¿å®è¡ãããŸãã ãã®ãããªã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããŠããããŒãã«é害ãçºçãããšããªã¹ãå ã®æ¬¡ã®ããŒãã§èªåçã«åèµ·åããŸãã åæ£ã¢ããªã±ãŒã·ã§ã³ãæ©èœããããŒãã®ãªã¹ãã¯ãããã»ã¹å ã§åçã«å€æŽã§ããŸãã
ãã€ããªããŒã¿ãæäœãã
Erlangã¯ïŒç¹ã«HiPEãšçµã¿åãããŠïŒãã€ããªããŒã¿ã®åŠçãéåžžã«é«éã§ãããããåã ã®ãããã®åŠçã«è³ããŸã§ãå ¥åãã€ããªããŒã¿ã®åŠçãæžã蟌ãããšã¯éåžžã«èªç¶ã§ãã ããã§ã¯ãJava 6ãšæ¯èŒããŠãErlangã¯æ°åã®é床ã§åã¡ãŸãã
çæ
Erlangã®äž»ãªæ¬ ç¹ã¯èšããŸã§ããªãããã®èšäºã¯å®å šã§ã¯ãããŸããã
- Unicodeæååã®ãµããŒãã®æ¬ åŠïŒèª°ããèšèªã®æ¬ é¥ãæ¬ ããŠããŸãããä»æ¥ãErlang R13Bã«ãµããŒããè¿œå ããããšãçŽæããŠããŸããããåŸ ã¡ããŠããŸãïŒ
- é ãæ°åŠãããã€ãã®æ·±å»ãªæ°åŠçèšç®ãæžãããšã¯éå¹ççã§ãã
- å°æ°ã®è¿œå ã©ã€ãã©ãªïŒ å¿ èŠãªãã®ã¯ãã¹ãŠæã£ãŠãããã©ã€ãã©ãªã®æ°ã¯çµ¶ããå¢ããŠããŸãããããã§ã.NETãCã®ãããªå€æ§æ§ããã¯ã»ã©é ãã§ãïŒ
- ãããã°ãããé«éã®ã°ã©ãã£ãã¯ã©ã€ãã©ãªããªããããErlangã§ã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ãäœæããŸããïŒãã¡ãããããšãã°wxErlangããããŸãããã©ã€ãã©ãªã¯ãŸã å®å šã§ã¯ãããŸããïŒã
ããããããããUnicodeæååã®ãµããŒãã®æ¬ åŠãé€ããŠããããã®ãã¹ãŠã®æ¬ ç¹ã¯ããã®èšèªãäœæãããç®çã§ã¯ãªããããåé¿ãããããå®éã«ã¯æ¬ ç¹ã§ã¯ãããŸããã ãŸãã é«è² è·ã§ã¹ã±ãŒã©ãã«ã§ä¿¡é Œæ§ã®é«ãã·ã¹ãã åãã«äœæãããŸããã åœåããã®èšèªã¯ç¹ã«éä¿¡ã§äœ¿çšããããã«äœæãããŸããããåŸã§å€æããããã«ãWebãµãŒããŒãåæ£ã·ã¹ãã ã®äœæã«æé©ã§ãã
ç¶ã
ããã§ããããæåã®èšäºãçµããã§ããããããã¯ãã§ã«ããªã倧ããããšãå€æããŸããã 次ã®èšäºã§ã¯ãåæ£åMnesiaããŒã¿ããŒã¹ïŒErlang / OTPã®äžéšïŒã®äœ¿çšã Amazon S3ããã³Amazon EC2ã®äœ¿çšã«ã€ããŠèª¬æããŸã ã
ãã®èšäºãžã®ã³ã¡ã³ãã«ãèšèªã®ã©ã®æ©èœã詳ããç¥ããããã«ã€ããŠæžããŠãã ããã
äžé£ã®èšäºã®ç¶ç¶- ããŒã2 ã