Last active
January 3, 2016 09:59
-
-
Save chrismccord/8446557 to your computer and use it in GitHub Desktop.
Nested Macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Example do | |
defmacro __using__(_options) do | |
quote do | |
Module.register_attribute __MODULE__, :attr, accumulate: true, persist: false | |
import unquote(__MODULE__) | |
end | |
end | |
defmacro append(attr) do | |
quote do | |
@attr unquote(attr) | |
end | |
end | |
defmacro append_twice(attr) do | |
quote do | |
append unquote(attr) | |
append unquote(attr) | |
end | |
end | |
end | |
defmodule UseExample do | |
use Example | |
append :foo | |
append_twice :foo | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment