Paul, I thought so as well, but ^n is necessary in a map. Otherwise it produces this error:
illegal use of variable n inside map key match, maps can only match on existing variable by using ^n Allen Madsen http://www.allenmadsen.com On Thu, Feb 23, 2017 at 3:05 AM, José Valim <[email protected] > wrote: > It is definitely a compiler bug, as that error message is not clear what > is happening. > > I will fix it on master. Thank you. > > > > *José Valim* > www.plataformatec.com.br > Skype: jv.ptec > Founder and Director of R&D > > On Thu, Feb 23, 2017 at 5:11 AM, Paul Schoenfelder < > [email protected]> wrote: > >> Isn't the pin operator unnecessary/invalid here? Two bindings in a match >> with the same name asserts that the two values are the same. >> >> Paul >> >> On Wed, Feb 22, 2017 at 9:44 PM Allen Madsen <[email protected]> >> wrote: >> >>> Your non-method example isn't the same as the method example. The >>> equivalent would be: >>> >>> [n, %{^n => result}] = [10, %{ 0 => 0, 10 => 55 }] >>> >>> In both cases I get `unbound variable ^n` on elixir 1.4.1. >>> >>> The behavior is surprising since this works: >>> >>> [n, ^n] = [10, 10] >>> >>> >>> Allen Madsen >>> http://www.allenmadsen.com >>> >>> On Wed, Feb 22, 2017 at 8:57 PM, pragdave <[email protected]> wrote: >>> >>> iex(16)> defmodule A do def _fib(n, %{ ^n => result }), do: result end** >>> (MatchError) no match of right hand side value: :error >>> >>> Notice this is a compilation error. >>> >>> Some background. This is part of a Fibonacci function that uses a cache >>> (the second parameter). If I get a cache hit, I want to return the >>> corresponding value. >>> >>> The concept works outside the context of a function parameter list: >>> >>> iex(16)> cache = %{ 0 => 0, 10 => 55 }%{0 => 0, 10 => 55} >>> iex(17)> n = 10; %{ ^n => result } = cache; result55 >>> >>> Elixir 1.5.0-dev (3094471) >>> >>> If it's a bug, I'll submit it. >>> >>> Cheers >>> >>> Dave >>> >>> >>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit https://groups.google.com/d/ms >>> gid/elixir-lang-core/6c948795-eafd-4a05-af81-857cf470daa5% >>> 40googlegroups.com >>> <https://groups.google.com/d/msgid/elixir-lang-core/6c948795-eafd-4a05-af81-857cf470daa5%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >>> >>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit https://groups.google.com/d/ms >>> gid/elixir-lang-core/CAK-y3Cs_N%3DG1TEhAk6LC5uAeeiy9o_gYix8% >>> 3DgzSK1icLEPjnFQ%40mail.gmail.com >>> <https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cs_N%3DG1TEhAk6LC5uAeeiy9o_gYix8%3DgzSK1icLEPjnFQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> 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 [email protected]. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/elixir-lang-core/CAK%3D%2B-Ttp5MuRotrkP8LhhVx9nHRMbXbSZ4 >> %3DFRnTBxV08tu1UNg%40mail.gmail.com >> <https://groups.google.com/d/msgid/elixir-lang-core/CAK%3D%2B-Ttp5MuRotrkP8LhhVx9nHRMbXbSZ4%3DFRnTBxV08tu1UNg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- > 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 [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/elixir-lang-core/CAGnRm4K1Ytq6iegKTSmbpUHAHKvFq > 5uEN_0nS1daMU4744pd0g%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4K1Ytq6iegKTSmbpUHAHKvFq5uEN_0nS1daMU4744pd0g%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3CvkJuDVLYEBWbZjVCc1N2zDWKEkVredWy%3D7qXQTATTTyQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
