Skip to content

Instantly share code, notes, and snippets.

@satom99
Created November 13, 2023 18:27
Show Gist options
  • Save satom99/32dfd61861bd9d1674c4f3db401836dd to your computer and use it in GitHub Desktop.
Save satom99/32dfd61861bd9d1674c4f3db401836dd to your computer and use it in GitHub Desktop.
Elixir variables that share a same name but are different
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