Last active
June 14, 2016 16:51
-
-
Save pguillory/d7c090e226c8aed619af6a4d1963c69c to your computer and use it in GitHub Desktop.
Built-in macros expanding to invalid code
This file contains hidden or 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
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 |
This file contains hidden or 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
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