Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created July 28, 2014 06:18
Show Gist options
  • Save AlexBaranosky/389a41f2537aafcdfe8c to your computer and use it in GitHub Desktop.
Save AlexBaranosky/389a41f2537aafcdfe8c to your computer and use it in GitHub Desktop.
iex(1)> expr = quote do: Unless.macro_unless(true, IO.puts "this should never be printed")
{{:., [], [{:__aliases__, [alias: false], [:Unless]}, :macro_unless]}, [],
[true,
{{:., [], [{:__aliases__, [alias: false], [:IO]}, :puts]}, [],
["this should never be printed"]}]}
iex(2)> res = Macro.expand_once(expr, __ENV__)
{{:., [], [{:__aliases__, [alias: false], [:Unless]}, :macro_unless]}, [],
[true,
{{:., [], [{:__aliases__, [alias: false], [:IO]}, :puts]}, [],
["this should never be printed"]}]}
iex(3)> IO.puts Macro.to_string(res)
Unless.macro_unless(true, IO.puts("this should never be printed"))
:ok
iex(4)> res = Macro.expand(expr, __ENV__)
{{:., [], [{:__aliases__, [alias: false], [:Unless]}, :macro_unless]}, [],
[true,
{{:., [], [{:__aliases__, [alias: false], [:IO]}, :puts]}, [],
["this should never be printed"]}]}
iex(5)> IO.puts Macro.to_string(res)
Unless.macro_unless(true, IO.puts("this should never be printed"))
:ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment