Difference between defmacro __using__(_) vs defmacro simple()?

When we define defamcro __ using__(_) and inside it we define defmacro simple().How can we access the inner simple() macro on the iex terminal?

What is the difference between these two?

Thanks!

1 Like

__using__/1 (the macro) is expanded when you use the implementing module.

Macros and functions need a module in which they are bound, so if you create macros or functions in a __using__/1 and you want to use that in iex you need to wrap that in a module.

Also for making macros available in IEx you need to require the implementig module to make them available and then you can call them qualified via that module. Flow is roughly like the following:

iex(1)> defmodule M do
...(1)>   use Foo
...(1)> end
iex(2)> require Foo
iex(3)> Foo.simple()
4 Likes