Variable binding in anonymous function's pattern matching

85 views
Skip to first unread message

X4lldux

unread,
Jan 18, 2015, 3:46:29 PM1/18/15
to elixir-l...@googlegroups.com
Hi,

why does this works:
iex(33)> x=1234; [c: 12345, b: 1234, a: 123] |>  Enum.filter(fn z -> case z do {key, ^x} -> IO.inspect key; {key, _} -> IO.inspect key; false end end)
:c
:b
:a
[b: 1234]

but this fails with an error:
iex(34)> x=1234; [c: 12345, b: 1234, a: 123] |>  Enum.filter(fn {key, ^x} -> IO.inspect key; {key, _} -> IO.inspect key; false end)
** (CompileError) iex:34: unbound variable ^x
    (stdlib) lists.erl:1352: :lists.mapfoldl/3
    (stdlib) lists.erl:1353: :lists.mapfoldl/3
    (elixir) src/elixir_translator.erl:297: :elixir_translator.translate/2
    (stdlib) lists.erl:1352: :lists.mapfoldl/3
    (elixir) src/elixir_fn.erl:26: :elixir_fn.translate_fn_match/2
    (elixir) src/elixir_clauses.erl:26: :elixir_clauses.match/3
    (elixir) src/elixir_clauses.erl:35: :elixir_clauses.clause/7


Regards,
X4lldux

Peter Hamilton

unread,
Jan 18, 2015, 3:59:03 PM1/18/15
to elixir-l...@googlegroups.com
Known issue. https://github.com/elixir-lang/elixir/issues/2061

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

X4lldux

unread,
Jan 18, 2015, 6:03:24 PM1/18/15
to elixir-l...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages