Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 14:00
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 alco/11254250 to your computer and use it in GitHub Desktop.
Save alco/11254250 to your computer and use it in GitHub Desktop.
defmodule MacroM do
defmacro h_transform(mod) do
IO.puts "Applying h_transform"
IO.inspect(mod)
end
defmacro la_transform(mod) do
IO.puts "Applying la_transform"
IO.inspect(mod)
end
defmacro defaugmod(head, body) do
{
{:., _, [Kernel, :access]},
_,
[
{:__aliases__, _, [modname]},
transformers
]
} = head
quote do
defmodule unquote(Module.concat([modname])) do
unquote(body)
end |> unquote(build_pipe(transformers))
end
end
defp build_pipe([h]) do
h
end
defp build_pipe([h|t]) do
{:|>, [], [h, build_pipe(t)]}
end
end
# $ elixir -r modaug_macro.ex modaug_test.ex
import MacroM
defaugmod LAXTester[h_transform, la_transform] do
def hello do
"Hello"
end
end
IO.puts LAXTester.hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment