Book Image

Elixir Cookbook

By : Paulo Pereira
Book Image

Elixir Cookbook

By: Paulo Pereira

Overview of this book

Table of Contents (16 chapters)
Elixir Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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)}
    Elixir version: #{v} (#{d})
    """
  2. 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)
    

How it works...