[erlang-questions] pattern matching & map

zxq9@REDACTED zxq9@REDACTED
Mon Nov 26 10:58:48 CET 2018


On 2018年11月26日月曜日 12時21分25秒 JST Oleg wrote:
>   Hi, all.
> 
> I try to do the pattern matching in a function definition with maps:
> 
> add_prms([{Name, Val}|T], #{Name := Vals} = Prms) ->
> 
> But erlc says me:
> 
> variable 'Name' is unbound
> 
> Is this is not supported yet?

You can match on literals as maps keys in a function head, but not dynamic values.

I believe you can match on dynamic values within a function body in a case:


  add_prms([{Name, Val} | T], Prms) ->
      case Prms of
          #{Name := Vals} -> % ...
  % ...


-Craig



More information about the erlang-questions mailing list