Skip to content

Instantly share code, notes, and snippets.

@cjbottaro
Created January 6, 2016 23:11
Show Gist options
  • Save cjbottaro/9ac0055c3f3b4824516b to your computer and use it in GitHub Desktop.
Save cjbottaro/9ac0055c3f3b4824516b to your computer and use it in GitHub Desktop.
defmodule MacroFun do
defmacro a(str, do: block) do
quote do
res = [a: unquote(str)]
unquote(block)
res
end
end
defmacro b(str) do
quote do
res ++ [b: unquote(str)]
end
end
def c(str) do
end
end
defmodule Run do
import MacroFun
def run do
result = a("hello") do
b("bleh")
c("blah")
end
IO.inspect result
end
end
Run.run
# Desired result: [a: "hello", b: "bleh", c: "blah"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment