<div dir="ltr">The problem is the key {a,N} in <span style="font-size:12.8px">#{{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.</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">// Björn-Egil</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-05-17 8:56 GMT+02:00 Avinash Dhumane <span dir="ltr"><<a href="mailto:nistrigunya@gmail.com" target="_blank">nistrigunya@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>avinash@veda:~/tws$ erl<br>Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]<br><br>Eshell V7.3 (abort with ^G)<br>1> M = #{{a, 1} => 100, {a, 2} => 200, {a, 3} => 300}.<br>#{{a,1} => 100,{a,2} => 200,{a,3} => 300}<br>2> lists:map(fun(N) -> #{{a, N} := V}= M, V div 10 end, lists:seq(1,3)).<br>* 1: illegal map key in pattern<br>3><br><br></div>I can get it working with maps:get/2<br><br>But, I seem not to understand when and where may variables be used in the pattern.<br><br></div>What am I missing?<br><br></div>Thanks<br></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>