programming erlang ch2 - andstudy/forge GitHub Wiki
์ค์น ๋ฐ ๋ฌธ์
์ค์น ํ ํ ์ผ
Erlang ์ฝ์์์ {{{file:get_cwd().}}} ๋ก ํ์ฌ working folder ๋ฅผ ํ์
ํ ํ
์์น์ {{{.erlang}}} ์ด๋ผ๋ ํ์ผ์ ๋ง๋ ๋ค.
p.42 ํ์ธ.
์ํ๋ ํด๋์ ์ผ๋ญ ์์ค ํ์ผ์ ์์ฑํ ํ console ๋ฑ์์ {{{c(์์ฑํ๋ชจ๋ํ์ผ์ด๋ฆ).}}} ํด์ .beam ํ์ผ์ ๋ง๋ค์ด์ผ ํ๋ค.
์ ์ ์ฐ์ฐ
2 + 3 * 4.
(2 + 3) * 4.
16#cafe * 32#sugar.
๋ณ์?
-
๋๋ฌธ์๋ก ์์ํ๋ค.
X = 1234567890. X. X * X. X = 1234. -
X ๋ ๋ณ์๊ฐ ์๋๋ค?
- ๋จ์ผ ํ ๋น ๋ณ์(single assignment variable)
-
bound, unbound
-
= ๋ ํ ๋น ์ฐ์ฐ์๊ฐ ์๋๋ค. ๋งค์นญ ์ฐ์ฐ์๋ค.
X = (2 + 4). {X |-> 6} Y = 10. {X |-> 6, Y |-> 10}
-
-
๋ณ์๋ฅผ ๋ฐ๊ฟ ์ ์๊ธฐ ๋๋ฌธ์, ์ ๊ธ(lock) ์ด ํ์์๋ค.
๋ถ๋ ์์์ ์
5/3.
5 div 3.
5 rem 3.
Atom
- enum ๊ณผ ๋น์ทํ๋ค.
- ์๋ฌธ์๋ก ์์ํ๋ค.
Tuple
-
์ค๊ดํธ { ์ } ๋ก ํํํ๋ค.
Person = {person, {name, joe}, {height, 1.82}, {footsize, 42}, {eyecolour, brown} }. F = {firstName, joe}. L = {lastName, armstrong}. P = {person, F, L}. Point = {point, 10, 45}. {point, X, Y} = Point. X. Y. Person={person, {name, {first, joe}, {last, armstrong}}, {footsize, 42}}. {_, {_, {_, Who}, _}, _} = Person. -
_ : anonymous variable (์ต๋ช ๋ณ์)
๋ฆฌ์คํธ
-
๊ฐ๋ณ์ ์ธ ๊ฒ์ ์ ์ฅํ ๋ ์ฌ์ฉ
-
๋๊ดํธ{{{ [ ] }}}๋ก ๋ฌถ๊ธฐ
[1 + 7, hello, 2 - 2, {cost, apple, 30 - 20}, 3]. head, tail ThingsToBuy = [{apples, 10}, {pears, 6}, {milk, 3}]. ThingsToBuy1 = [{orange, 4}, {newspaper, 1} | ThingsToBuy]. [Buy1 | ThingsToBuy2] = ThingsToBuy1.
๋ฌธ์์ด
Name = "Hello"
[83, 117, 114, 112, 114, 105, 115, 101].
export ๊ฐ ๊ท์ฐฎ์ผ๋ฉด
{{{-compile(export_all).}}} ๋ฅผ ์ ์ธํด ์ค๋ค.