It is possible to use Elixir as if it were an interpreted language. Code is evaluated at the source level, eliminating the need to compile it before use. One of the examples of the usage of Elixir in the scripted mode is the test suite inside a Mix project. There, under the tests
directory, you will find files with the .exs
extension.
The convention in Elixir is to use the .ex
extension in files that should be compiled and the .exs
extension in files that should be interpreted.
To use the Elixir code without compiling it, follow these steps:
Create a file named
my_script.exs
and add the following code:%{:date => d, :version => v} = System.build_info IO.puts """ Command line arguments passed: #{inspect(System.argv)} Elixir version: #{v} (#{d}) """
Run the code in your terminal window:
> elixir my_script.exs --demo –T –v Command line arguments passed: ["--demo", "–T", "-v"] Elixir version: 1.0.0 (Wed, 10 Sep 2014 17:30:06 GMT)