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

Robert Virding rvirding@REDACTED
Sat Apr 4 02:08:58 CEST 2015


Also any reordering the compiler does in the way it tests the patterns is
guaranteed not to change the semantics of the original. The resultant code
will always behave as if the clauses had been tested top-to-bottom as
written.

Robert


On 1 April 2015 at 21:28, Björn-Egil Dahlberg <wallentin.dahlberg@REDACTED>
wrote:

> 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
>>
>
>
> _______________________________________________
> 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/20150404/29eb7ac7/attachment.htm>


More information about the erlang-questions mailing list