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).}}} ๋ฅผ ์„ ์–ธํ•ด ์ค€๋‹ค.