[erlang-questions] function clauses with maps (18.3)

Björn-Egil Dahlberg <>
Wed Mar 30 22:54:58 CEST 2016


This is a current limitation with maps and bitsyntax. Variables has to be
bound before being used as an expression in a pattern.

2016-03-30 22:01 GMT+02:00 Luis Azedo <>:

> Hi,
>
> this doesn't compile in 18.3. is it supposed to work with the maps spec ?
> maybe in a later release ?
>
> -spec my_match(atom(), atom(), map()) -> any().
> my_match(Classification, CarType, #{my_key := #{ Classification := #{
> <<"cars">> := #{ CarType := Map}}}}) ->
> ....
> variable 'Classification' is unbound
> variable 'CarType' is unbound
>
>
> this works but we're not taking advantage of function clauses.
>
> my_match(Classification, CarType, M ) ->
>     #{my_key := #{ Classification := #{ <<"cars">> := #{ CarType :=
> Map}}}} = M,
>     Map.
> ....
>
> TIA
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160330/71b31f78/attachment.html>


More information about the erlang-questions mailing list