Skip to content

Instantly share code, notes, and snippets.

@cpjk
Last active September 15, 2015 05:07
Show Gist options
  • Save cpjk/bf87eec0ed8c107c8117 to your computer and use it in GitHub Desktop.
Save cpjk/bf87eec0ed8c107c8117 to your computer and use it in GitHub Desktop.
# file1.ex
defmodule A do
defmacro __using__(_env) do
quote do
Module.register_attribute __MODULE__, :rules, accumulate: true
end
end
defmacro register() do
@rules
|> Enum.each fn(x) ->
#....
#....
end
quote do
# something
end
end
defmacro define_rule() do
quote do
@rules {"rule"}
end
end
end
require A
# file2.ex
defmodule B do
use A
A.define_rule
A.register # @rules is not yet defined when this macro is expanded
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment