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; result
55
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 elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6c948795-eafd-4a05-af81-857cf470daa5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 <prag...@gmail.com> wrote:
iex(16)> defmodule A do def _fib(n, %{ ^n => result }), do: result end ** (MatchError) no match of right hand side value: :errorNotice 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; result 55Elixir 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 elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6c948795-eafd-4a05-af81-857cf470daa5%40googlegroups.com.
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 elixir-lang-co...@googlegroups.com.
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.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6c948795-eafd-4a05-af81-857cf470daa5%40googlegroups.com.
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 elixir-lang-core+unsubscribe@googlegroups.com.
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.
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 view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK%3D%2B-Ttp5MuRotrkP8LhhVx9nHRMbXbSZ4%3DFRnTBxV08tu1UNg%40mail.gmail.com.To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4K1Ytq6iegKTSmbpUHAHKvFq5uEN_0nS1daMU4744pd0g%40mail.gmail.com.
It is definitely a compiler bug, as that error message is not clear what is happening.I will fix it on master. Thank you.
[n, %{^n => result}] = [10, %{ 0 => 0, 10 => 55 }]
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a5434bc2-b63d-4038-b51d-ce7c780eac89%40googlegroups.com.