[erlang-questions] Pattern match error in Maps
Björn-Egil Dahlberg
wallentin.dahlberg@REDACTED
Tue May 17 09:28:29 CEST 2016
The problem is the key {a,N} in #{{a, N} := V}. The compiler only accepts
literals or variables, not arbitrary expressions. Here you need to eval
{a,N} first and bind it to a variable.
// Björn-Egil
2016-05-17 8:56 GMT+02:00 Avinash Dhumane <nistrigunya@REDACTED>:
> avinash@REDACTED:~/tws$ erl
> Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:2:2] [async-threads:10]
> [hipe] [kernel-poll:false]
>
> Eshell V7.3 (abort with ^G)
> 1> M = #{{a, 1} => 100, {a, 2} => 200, {a, 3} => 300}.
> #{{a,1} => 100,{a,2} => 200,{a,3} => 300}
> 2> lists:map(fun(N) -> #{{a, N} := V}= M, V div 10 end, lists:seq(1,3)).
> * 1: illegal map key in pattern
> 3>
>
> I can get it working with maps:get/2
>
> But, I seem not to understand when and where may variables be used in the
> pattern.
>
> What am I missing?
>
> Thanks
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160517/ad8889e1/attachment.htm>
More information about the erlang-questions
mailing list