Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # Running Elixir
  2.  
  3. 1. Run the elixir command with the relative path of the Elixir file:
  4.  
  5. ```
  6. $ elixir lib/servy.ex
  7. ```
  8.  
  9. The file gets compiled into bytecode (in memory) and then run on an Erlang virtual machine.
  10.  
  11. 2. Fire up an iex (Interactive Elixir) session and then use the c helper function to compile and run the file:
  12.  
  13. ```
  14. $ iex
  15.  
  16. iex> c "lib/servy.ex"
  17. ```
  18. The c helper function compiles the given file in memory, the module (Servy in this case) is loaded into the session, and any code outside of the module is interpreted.
  19.  
  20. To exit the iex session, press Ctrl+C twice.
  21.  
  22. 3. Alternatively, you can tell iex to interpret an Elixir file while starting by passing the relative path of the file:
  23.  
  24. ```
  25. $ iex lib/servy.ex
  26. ```
  27.  
  28. 4. When you start a standard iex session, it doesn't know about the paths and dependencies of a mix project. So to start a session in the context of a project, you need to pass the -S mix option:
  29.  
  30. ```
  31. $ iex -S mix
  32. ```
  33.  
  34. 5. Finally, to recompile a module while in iex, use the r helper function:
  35.  
  36. ```
  37. iex> r Servy
  38. ```
  39.  
  40. This recompiles and reloads the given module, which is Servy in this case.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement