[erlang-questions] pattern matching & map
Oleg
lego12239@REDACTED
Mon Nov 26 11:21:18 CET 2018
On Mon, Nov 26, 2018 at 06:58:48PM +0900, zxq9@REDACTED wrote:
> 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} -> % ...
> % ...
Already done like this :-), but thought that i do something wrong with map pattern matching in function.
Thanks!
--
Олег Неманов (Oleg Nemanov)
More information about the erlang-questions
mailing list