[erlang-questions] Illegal map key in pattern

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Thu Aug 15 14:12:46 CEST 2019

Den mån 5 aug. 2019 kl 13:45 skrev Raimo Niskanen <

> >
> > But maybe it's "just" something that was a challenge to implement, and
> > will be fixed to match the current documentation in a future release...
> I think it is precisely like that.  It is documented as it was intended,
> but implementing it was a challenge so it got only partly implemented.
> (constructing a new term for map lookup in the context of a pattern match
> proved an unexpectedly hard problem, I guess)

IIRC the case that was troublesome was the failure case, say

K = a

case Map of
   #{ K + 1 := V } -> V;

Meaning it is essentially no trouble to evaluate the key expression before
the case expression, however the semantics for what should happen if the
key expression fails were never really defined.
The easy option it just to throw an exception and that makes some sort of
sense, but it could make more sense that we say "the pattern does not
match" and then test the next clause in the case expression. This latter
option is also a bit harder to implement ofc. The core and kernel language
does not really expect this behaviour :) go and figure ^^

In other words - it is not implemented because we, well I, missed this case
when defining the semantics.

My bad.

> So it is a known limitation, to us that know it ;-)
> unfortunately not nicely documented,
> and the goal is to fix it some day...
> http://erlang.org/pipermail/erlang-questions/2016-May/089269.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190815/6de7c6af/attachment.htm>

More information about the erlang-questions mailing list