Reputation: 103
I'm having hard time to load a module into another module using Elixir language.
For example, I have 2 files shown below:
a.ex
defmodule A do
def a do
IO.puts "A.a"
end
end
b.ex
defmodule B do
require A
def b do
IO.puts "B.b"
A.a
end
end
B.b
I tried to execute b.ex. Then I got error shown below:
$elixir b.ex
** (CompileError) b.ex:2: module A is not loaded and could not be found
Upvotes: 8
Views: 2827
Reputation: 3067
In your file b.ex
remove the B.b from the last line
Then in your project directory run Iex like so
iex -S mix
This will load iex and load your modules correcly
Then you can just do B.b
and you'll see:
B.b
A.a
:ok
Also, make sure your a.ex
and b.ex
files are in the lib/
directory of your elixir project
Upvotes: 4