Skip to content

Instantly share code, notes, and snippets.

@pguillory
Last active June 14, 2016 16:51
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 pguillory/d7c090e226c8aed619af6a4d1963c69c to your computer and use it in GitHub Desktop.
Save pguillory/d7c090e226c8aed619af6a4d1963c69c to your computer and use it in GitHub Desktop.
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