Skip to content

Instantly share code, notes, and snippets.

@pguillory
Last active Jun 14, 2016
Embed
What would you like to do?
Built-in macros expanding to invalid code
case(:condition) do
x when x in [false, nil] ->
nil
_ ->
:ok
end
case(:condition) do
x when Enum.member?([false, nil], x) ->
nil
_ ->
:ok
end
# cannot invoke remote function Enum.member?/2 inside guard
block = quote do
if :condition do :ok end
end
block
|> Macro.expand_once(__ENV__)
|> Macro.to_string
|> IO.puts
block
|> Macro.prewalk(&Macro.expand(&1, __ENV__))
|> Macro.to_string
|> IO.puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment