Elixir Sightseeing Tour

Elixir Sightseeing Tour

Faafc04d9e69b73b9f49995fd4c94d4d?s=128

Andrea Leopardi

September 26, 2019
Tweet

Transcript

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
  13. 13.
  14. 14.
  15. 15.
  16. 16.
  17. 17.
  18. 18.
  19. 19.
  20. 20.
  21. 21.
  22. 22.
  23. 23.
  24. 24.
  25. 25.
  26. 26.
  27. 27.
  28. 29.
  29. 30.
  30. 33.
  31. 35.

    case some_expression do 1 -> "it's one!" {_, _} ->

    "it's a 2-elem tuple!" _other -> "it's something else" end
  32. 37.
  33. 41.
  34. 42.
  35. 43.
  36. 44.
  37. 45.
  38. 47.
  39. 48.
  40. 49.
  41. 50.
  42. 51.
  43. 52.
  44. 53.
  45. 54.
  46. 56.
  47. 57.
  48. 59.
  49. 60.
  50. 62.
  51. 63.

    send(dest_pid, {self(), {:add, 1, 7}}) receive do {:add_response, response} ->

    IO.puts("Response: #{response}") after 1000 -> IO.puts("Timeout :(") end
  52. 64.
  53. 65.
  54. 66.
  55. 67.
  56. 68.
  57. 69.
  58. 70.
  59. 71.

    ref = Process.monitor(dest_pid) send(dest_pid, {self(), {:add, 1, 7}}) receive do

    {:add_response, response} -> IO.puts("Response: #{response}") {:DOWN, ^ref, _, _, _} -> IO.puts("Process went down") after 1000 -> IO.puts("Timeout :(") end
  60. 72.
  61. 73.
  62. 74.
  63. 75.
  64. 76.
  65. 77.
  66. 78.
  67. 79.
  68. 80.
  69. 81.
  70. 82.
  71. 83.
  72. 84.
  73. 85.
  74. 86.
  75. 87.
  76. 89.

    two_code = quote do 1 + 1 end quote do

    add(1, unquote(two_code)) end
  77. 90.

    if condition do expression end quote do case unquote(condition) do

    true -> unquote(expression) false -> nil end end
  78. 91.
  79. 92.
  80. 93.
  81. 94.
  82. 95.
  83. 96.