Skip to content

Instantly share code, notes, and snippets.

@chrismccord
Last active January 3, 2016 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismccord/8446557 to your computer and use it in GitHub Desktop.
Save chrismccord/8446557 to your computer and use it in GitHub Desktop.
Nested Macro
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