What is `=INFO REPORT====` where is it coming from ? how to surpress it?

Unless you did something wrong, it should only recompile touched modules. But if you change a module that is used, included or required, you need to recompile all the modules that use it that way.

mix app.tree can help you to find out how compiletime dependencies.

I would be curious about what times you are seeing. mix compile --force in Ecto, which has 35k LOC over 68 files takes 5 seconds in my machine. And that is a full compilation. Elixirā€™s compiler is incremental so most times you are waiting considerably less.

Just to clarify: mix compile does all of it for you, you donā€™t have to track anything. mix compile should also be fast enough, if the concern is the experience (quitting the shell and restarting it), then you can use file system watchers or invoke recompile in the shell directly.

That is about dependencies between applications. mix xref graph is the one that is about modules but you are generally not supposed to care.

EDIT: the clarifications are not for you @NobbZ :slight_smile: just expanding your comments.

1 Like

Iā€™m new to Elixir as well, and I know some Erlangā€“but I also know Ruby pretty well, and I would describe Elixir as rubified Erlang, so Elixir has not been as difficult for me as Erlang was. Learning recursion in Erlang took a while.

In any case, I was very confused when I saw modules defined like this in Elixir:

defmodule My do
  import A
  require B
  use C

   ...
   ..
end

The only one of import, require, and use that I could understand was import, which allows you to use the unqualified names of the functions defined in A, e.g. do_stuff() v A.do_stuff(). In other words, import just affects the namespacing of names.

On the other hand, require and use employ black magic to inject function definitions (and other definitions) into the module where the require or use statement appears. The black magic is accomplished via an Elixir feature called macros, which is an advanced topic. I got so frustrated not understanding what the heck was going on when I saw use, require, and import lumped together, that I skipped straight away to the macros section of my book. If you want to gain some understanding of require and use then you need to learn about macros. In any case, thatā€™s where test() and assert() come from.

Just yesterday, I was trying to figure out what doctest KV does. Well, doctest is a macro and you are passing it the argument KV, and the macro performs some black magic which allows you to doā€¦something related to testing!

doctest is a macro that searches a specified module for code examples and automatically generates test cases.

See here.

2 Likes

That is for the interpreter runner, not when running in distribution mode. You can do the same with elixir.

There is no black magic in require. :slight_smile: All require does is to allow you to invoke a macro in some module. But if you only do require Foo and nothing more, nothing should happen.

2 Likes

Aargh! <mental model cracking> So, all macros are expanded at compile time whether or not they are require()'d anywhere?

Oh yeah, and this: require() insures that the module you are requiring gets loaded before the module containing the require statement.

You canā€™t use a macro without having requireing or includeing the module that contains the macro.

1 Like

I know thatā€™s not true. Hereā€™s proof:

defmodule My do
  defmacro go() do
    quote do
      def greet(), do: IO.puts "hello"
    end
  end
end

defmodule Test do
  require My
  My.go
end

Test.greet

Output:

~/elixir_programs$ iex macros2.ex

Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

hello

Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>

No include required. Wait a minuteā€¦what the heck is include? I wrote include and I was thinking import.

You always have to require a module before you call a macro on it. That is requireā€™s only purpose. In the example above, you used require. Note that import also requires it for you.

1 Like

I did NOT know that. Everything Iā€™ve read says that you have to require macrosā€¦but import works as well. Thanks!

Yeah, by include I meant import. I tend to not use this one at all, I consider it polluting my namespace and Iā€™m currently doing a lot of C, where we have #include preprocessor directiveā€¦ Perhaps I was confused by that?

Still, in your ā€œproofā€ of not needing to require or import modules, you used require, which I told you is a must have.