[~/src_elixir]$ pwd -P /Users/casiano/Google Drive/src/elixir
[~/Google Drive/src/elixir]$ cat sum.elixir defmodule MyList do def sum([]), do: 0 def sum([ head | tail ]), do: head + sum(tail) end IO.puts MyList.sum [1, 2, 3, 4]
[~/Google Drive/src/elixir]$ elixir sum.elixir /Users/casiano/Google Drive/src/elixir/sum.elixir:1: redefining module MyList 10
[~/src_elixir]$ iex Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] Interactive Elixir (0.12.0) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> c("sum.elixir") sum.elixir:1: redefining module MyList 10 [MyList] iex(2)> MyList.sum [1, 2, 3, 4, 5] 15 iex(3)>
Es posible escribir un módulo en la consola:
iex(3)> defmodule MyModule do ...(3)> def hello do ...(3)> IO.puts "Another Hello" ...(3)> end ...(3)> end {:module, MyModule, <<70, 79, 82, 49, 0, 0, 7, 104, 66, 69, 65, 77, 65, 116, 111, 109, 0, 0, 0, 124, 0, 0, 0, 13, 15, 69, 108, 105, 120, 105, 114, 46, 77, 121, 77, 111, 100, 117, 108, 101, 8, 95, 95, 105, 110, 102, 111, 95, 95, 4, ...>>, {:hello, 0}} iex(4)> MyModule.hello Another Hello :ok