[erlang-questions] pattern matching & map

Per Hedeland per@REDACTED
Mon Nov 26 12:35:51 CET 2018

On 2018-11-26 12:16, zxq9@REDACTED wrote:
> On 2018t1126åÜå 14B1224Ò JST Oleg wrote:
>> On Mon, Nov 26, 2018 at 11:12:39AM +0100, MichaB MuskaBa wrote:
>>> In OTP 21 you could use the map_get/2 guard:
>>> add_prms([{Name, Val}|T], Prms) when map_get(Name, Prms) =:= Val ->
>> Wow. That's great! But why we can't simply do:
>> add_prms([{Name, Val}|T], #{Name := Vals} = Prms) ->
>> :-)?
> IIRC is is because `Name` isn't really being used to match (unify) there, it is being used to call into map code, which is slightly different and only abstracted by the magical #{} syntax. There is an explanation of this somewhere on list, but I don't have the link handy.

AFAIR the "problem" is that the order of evaluation of function
arguments is undefined. The #{Name := Vals} matching requires that
'Name' is bound (there is no "magic" AFAIK) - and it *would* be in
the above function head, if argument evaluation was defined to be

--Per Hedeland

More information about the erlang-questions mailing list