Pattern matching on something like the example below is a bit tricky, because
of the semantics of pattern matching:
[n, %{^n => result}] = [10, %{ 0 => 0, 10 => 55 }]
^n means take the previous value of the variable "n" - but since we're in the
pattern there's no previous value (unless it was bound earlier). The pattern is
not evaluated left to right, but considered as a whole, e.g. you write {x, x}
to match on a tuple with two identical values. This could leave us with another
possibility:
[n, %{n => result}] = [10, %{ 0 => 0, 10 => 55 }]
This, in turn, presents a rather nasty performance issues. Since the pattern is
evaluated as a whole, we could write [n, %{n => n}] or even worse [n, %{x =>
n}] - matching becomes extremely complex in those situations. Because of this,
matching on a map keys with non-literals is not allowed.
Michał.
On 23 Feb 2017, 17:17 +0100, pragdave <[email protected]>, wrote:
>
>
> On Thursday, February 23, 2017 at 2:05:59 AM UTC-6, José Valim 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.
>
> Does that mean I won't be able to write this?
> --
> 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/a5434bc2-b63d-4038-b51d-ce7c780eac89%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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/2793822f-99cc-42ce-8a4d-5db69a8fbfcb%40Spark.
For more options, visit https://groups.google.com/d/optout.