Created
January 6, 2016 23:11
-
-
Save cjbottaro/9ac0055c3f3b4824516b to your computer and use it in GitHub Desktop.
This file contains 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 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