Pass module to a macro

You don’t get values into a macro but ASTs.

The AST generated by the term Plug is {:__aliases__, [alias: false], [:Plug]}. To get the actual value out of it, you need to expand it.

A small iex session to show it a little bit better:

iex(1)> quote do: Plug    
{:__aliases__, [alias: false], [:Plug]}
iex(2)> (quote do: Plug) |> Macro.expand(__ENV__)
Plug

As I told you a couple of weeks ago, you need to make clear to yourself the differences of compile and runtime as well as the different forms of representing data at the various stages of the lifecycle of a programm from source to executable.

3 Likes