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/msgid/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/msgid/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/msgid/elixir-lang-core/CAK%3D%2B-Ttp5MuRotrkP8LhhVx9nHRMbXbSZ4%3DFRnTBxV08tu1UNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to