I understand that the compilation process (simplified) is something like:
source code → Initial Parsing → AST → Expansion → expanded AST → Bytecode Generation → bytecode
I am curious is there an attempt by the compiler to compile the first AST before proceeding to expansion. I am making this guess based on the observation is make from the below code.
This does not compile with error: undefined function hello/1
when i expected it to; as after AST expansion function hello
would have been there for invocation already.
defmodule Foo do
defmacro my_macro() do
quote do
def hello(person) do
IO.inspect person
end
end
end
end
defmodule Bar do
require Foo
Foo.my_macro()
hello("Bob")
end
But this does
defmodule Foo do
defmacro my_macro() do
quote do
def hello(person) do
IO.inspect person
end
end
end
end
defmodule Bar do
require Foo
Foo.my_macro()
def run() do
hello("Bob")
end
end