[erlang-questions] Warning not emitted on string matching clauses

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Wed Apr 1 21:28:52 CEST 2015


The compiler doesn't really "reorder" the clauses. It builds a match tree
depending on types, values and variables. In the current implementation it
does so by inspecting all clauses left to right.

You can inspect the matching tree by compiling to kernel, i.e. erlc
+to_kernel t.erl

// Björn-Egil

2015-04-01 20:57 GMT+02:00 Fred Hebert <mononcqc@REDACTED>:

> On 04/01, Pierre Fenoll wrote:
>
>> Ferd on IRC mentioned that the compiler might feel free to reorder
>> clauses.
>>
>
> The compiler would only reorder clauses that are free to do so.
>
> For example:
>
>    f(a) -> 1;
>    f(b) -> 2;
>    f(X) when is_atom(X) -> 3;
>    f([_|_]) -> 4;
>    f({_}) -> 5.
>
> Would let the compiler possibly reorder 1 & 2, and maybe 4 & 5. But the
> presence of a guard clause or ambiguous matches would prevent it from doing
> more than that, if my understanding is accurate.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150401/b62186f4/attachment.htm>


More information about the erlang-questions mailing list