[erlang-questions] pattern matching & map

zxq9@REDACTED zxq9@REDACTED
Mon Nov 26 12:16:33 CET 2018


On 2018年11月26日月曜日 14時12分24秒 JST Oleg wrote:
> On Mon, Nov 26, 2018 at 11:12:39AM +0100, Michał Muskała 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.

-Craig



More information about the erlang-questions mailing list