Elixir - Application24 Sep 2017
- load paths
- evaluate or compile
- start/stop in IEx
Elixir compiles all source files found in
(project configuration option in mix.exs).
elixirc_paths option can be set on per environment basis -
see Elixir - Testing.
sometimes it’s necessary to load specific file that is located
somewhere else (say, when running
exs script file that depends
exs file) - use
Code.require_file/2 in this case:
relative_to argument is not passed, all paths
are considered to be relative to project root directory.
evaluate or compile
exfiles are meant to be compiled
exsfiles are used for scripting
each module is compiled into its own bytecode (
- if file doesn’t contain modules no bytecode files are generated
- it doesn’t matter if module is defined in
exfile (file extension doesn’t matter at all - module can be defined in
Exampleis compiled into
- code typed in IEx is always evaluated - not compiled
- code is evaluated iff when typed in IEx directly
- never benchmark by typing code in IEx directly
compile in memory
in these cases bytecode modules are not written to disk - only loaded in memory:
$ iex foo.exs
compiles file in memory and loads it into IEx.
$ elixir foo.exs
compiles file in memory and executes it (it’s like running any other script in UNIX shell).
iex> import_file "foo.exs"
evaluates the contents of the file as if it were directly typed into IEx
in spite of what is said above imported file is compiled in memory.
compile to beam file
$ elixirc foo.exs
compiles file and executes it.
iex> c "foo.exs"
compiles file and loads it into IEx.
iex starts IEx without running your app (same as
mix run --no-halt- run your Elixir app without IEx
iex -S mix- start IEx and run your Elixir app inside (same as
run is a default Mix task - specify it explicitly
if it’s necessary to pass any task options.
mix phx.server- run your Phoenix app without IEx
iex -S mix phx.server- start IEx and run your Phoenix app inside (looks like
start/stop in IEx
iex> Application.start(:neko) iex> Application.stop(:neko) iex> Application.stop(:logger) iex> Application.ensure_all_started(:neko)