O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using a module in the scripted mode

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.

How to do it…

To use the Elixir code without compiling it, follow these steps:

  1. 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)} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required