introduction to erlang/otp
TRANSCRIPT
Erlang
WindowsOKOK
Erlang ITPHPer
EC
(`)
Erlang
Ericsson(, )
1982-1986(Lisp, Prolog, Parlog)
1987Erlang
1998
ErlangOTP(Open Telecom Platform)SDKErlang/OTP
(Agner Krarup Erlang)
ERicsson LANGuage
Ericsson
http://www.atmarkit.co.jp/news/200704/27/erlang.html
UP
TwitterErlangIM"ejabberd"Web
(^_^;)
http://www.atmarkit.co.jp/news/200704/27/erlang.html
http://www.ejabberd.im/
Lisp/Scheme
LISPLispScheme*nixWindowsMIT-GNU Scheme
EmacsEmacs-Lisp
LispScheme
Web
Erlang
Windows
Web
TutorialReference
PHPerErlang(w
PHPer
DIS
Erlang
Erlang()
WebErlang
Erlang/OTP
http://www.erlang.org/ DL2008/07R12B-3
"otp"Erlang/OTP
Erlang 5.6(.3)
ErlangOTP
C#.Net
Windows
http://www.erlang.org/ DL
BitTorrentDL
"C:\Program File\erl5.6.3"
PATH
"erts-5.6.3\bin"PATH(epmd)
Erlang
- Erlang -
"Hello, Erlang!"
"Hello, Erlang!"
"hello.erl"
-module(hello).-export([start/0]).
start() -> io:format("Hello, Erlang!~n").
"Hello, Erlang!"
CDerl(Erlang)
C:\in_vitro\erlang>erlEshell V5.6.3 (abort with ^G)1> c(hello).{ok,hello}2> hello:start().Hello, Erlang!ok
"-module(hello)."
""
Erlang".erl"
"-export([start/0])."
()
Cexport
"/0"()
start() ->
io:format("Hello, Erlang!~n").
start()
io:format printf()
"."()
"c(hello)."
"hello.erl""hello.beam"
".erl"
' c("dir1/hello2"). '
"h()."
"halt()."
"hello:start()."
":()."
Erlang
("_")
Erlang
C:\in_vitro\erlang>erlEshell V5.6.3 (abort with ^G)1> Var1 = 100.1002> Var1_2 = 200.2003> var2 = 300.** exception error: no match of right hand side value 3004> Var2-1 = 400.* 1: illegal pattern
OK!
NG!
Erlang
9> Var1 = 100.10010> Var1 = "ABCD".** exception error: no match of right hand side value "ABCD"11> b().Var1 = 100ok
(bind)
erlb()f()
11> b().Var1 = 100ok12> f().ok13> Var1 = "ABCD"."ABCD"
Erlang
(atom)
C
""RubySymbol
PHPdefine()
"_", "@"
17> hello.hello18> 'Friday Night'.'Friday Night'19> '[email protected]'.'[email protected]'
Erlang
(tuple)
C
1> X = {1, "hello", world }.{1,"hello",world}2> Y = { {orange, 100}, {apple, 300} }.{{orange,100},{apple,300}}
3> {V1, V2} = X.** exception error: no match of right hand side value {1,"hello",world}4> {V1, V2, V3} = X.{1,"hello",world}5> V1.16> V2."hello"7> V3.world
9> V1 = { apple, 100 }.{apple,100}10> V2 = { orange, 200 }.{orange,200}11> { apple, Price } = V1.{apple,100}12> { orange, Price_orange } = V1.** exception error: no match of right hand side value {apple,100}13> { orange, Price_orange } = V2.{orange,200}14> { Price, Price_orange }.{100,200}
Erlang
(list)
[]
1> X = [1, "Hello", world, 2 + 3, { apple, 10 }, [ 4, 5, 6 ] ].[1,"Hello",world,5,{apple,10},[4,5,6]]
[]
1> X = [1, "Hello", world, 2 + 3, { apple, 10 }, [ 4, 5, 6 ] ].[1,"Hello",world,5,{apple,10},[4,5,6]]
HeadTail
"|"list
lists:nth(N, List)
1
2> lists:nth(1, X).13> [H | T] = X.[1,"Hello",world,5,{apple,10},[4,5,6]]4> H.15> T.["Hello",world,5,{apple,10},[4,5,6]]
Erlang
(record)
(.hrl)includeerlrr()
records.hrl
-record(person, { %% name = "anonymous", %% age, weight }).
erlrr()
1> rr("records.hrl").[person]2> V1 = #person{}.#person{name = "anonymous",age = undefined, weight = undefined}3> V2 = #person{ name = "Jon", age = 20, weight = 60 }.#person{name = "Jon",age = 20,weight = 60}4> V3 = #person{ name = "Smith", age = 30, weight = 58 }.#person{name = "Smith",age = 30,weight = 58}5> #person{ name = N, age = A, weight = W } = V3.#person{name = "Smith",age = 30,weight = 58}6> [ N, A, W ].["Smith",30,58]
Erlang
(function)
Arity
-module(funtest1).-export([funtest/0, funtest/1, funtest/2]).funtest() -> -1.funtest(N) -> N * 2.funtest(N, M) -> N + M.1> c(funtest1).{ok,funtest1}2> { funtest1:funtest(),funtest1:funtest(10),funtest1:funtest(20, 30) }.{-1,20,50}
""
""";"
-module(funtest2).-export([fact/1]).fact(N) when N > 0 -> N * fact(N - 1);fact(0) -> 1.1> c(funtest2).{ok,funtest2}2> funtest2:fact(5).120
fun()
1> Double = fun(X) -> X * 2.* 1: syntax error before: '.'1> Double = fun(X) -> X * 2 end.#Fun2> L = [ 1, 2, 3, 4].[1,2,3,4]3> lists:map(Double, L).[2,4,6,8]
ifcasetry-catch
URL
http://www.erlang.org/
http://www.trapexit.org/Category:CookBook
Tutorial
http://erlang-users.jp/
http://dsas.blog.klab.org/archives/cat_50029902.html
DSAS