Created
November 13, 2023 18:27
-
-
Save satom99/32dfd61861bd9d1674c4f3db401836dd to your computer and use it in GitHub Desktop.
Elixir variables that share a same name but are different
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
ast = | |
{:fn, [], | |
[ | |
{:->, [], | |
[ | |
[ | |
{:a, [counter: 1], nil}, | |
{:a, [counter: 2], nil} | |
], | |
{{:a, [counter: 1], nil}, {:a, [counter: 2], nil}} | |
]} | |
]} | |
Macro.to_string(ast) | |
# "fn a, a -> {a, a} end" | |
{fun, _binding} = Code.eval_quoted(ast) | |
fun.(:foo, :bar) | |
# {:foo, :bar} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment