Elixir ships with four binaries for compilation, project building, and more.
iexa shell for evaluating elixir expressions and experimenting with your source code in real-time.elixirexecutes compiled elixir files or elixir "scripts" (.exs files)elixircelixir compilermixelixir's fantastic build tool for project creation, dependency management, tasks, and more.
iex is an essential tool for exploring language features and quickly
experimenting with code. Any valid Elixir expression can be evaluated and
using the h helper function provides instant access to module documentation.
$ iex
Interactive Elixir (0.11.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 1 + 1
2
iex(2)> h Enum.first
def first(collection)
Returns the first item in the collection or nil otherwise.
Examples
┃ iex> Enum.first([])
┃ nil
┃ iex> Enum.first([1, 2, 3])
┃ 1
iex(3)>
The c helper function compiles files and loads them into the shell.
#hello.ex
defmodule Hello do
def world do
IO.puts "Hello Word!"
end
endiex(2)> c "hello.ex"
[Hello]
iex(3)> Hello.world
Hello Word!
:ok
iex(4)>
$ mix new hello_elixir
* creating README.md
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/hello_elixir.ex
* creating lib/hello_elixir
* creating lib/hello_elixir/supervisor.ex
* creating test
* creating test/test_helper.exs
* creating test/hello_elixir_test.exs
Your mix project was created successfully.
You can use mix to compile it, test it, and more:
cd hello_elixir
mix compile
mix test
Run `mix help` for more information.
Mix creates a directory structure and application manifest that follows Erlang/OTP conventions and plays nicely with Erlang applications.
- Source code lives in
lib/hello_elixir/src/. Any.exfile you place in lib or subdirectories of lib will be automatically compiled and loaded by mix. - Test are defined as elixir scripts with
.exsextensions in thesrc/testdirectory. Any.exsfile loaded within test and test subdirectories will be automatically included in the test suite. mix.exscontains your projects configuration and is where you define your dependencies.
To see what mix has to offer, simply invoke mix help and start exploring.
Most useful commands include:
mix deps.getRetrieve and compile all dependenciesmix runRuns your project, compiling sources where neccessarymix testRuns all tests located insrc/test/*/**.exsmix test [test_file_path]- Runs a specific testiex -S mixLoads Elixir's interactive shell with all mix dependencies and is incredibly useful for experimenting your project code