[erlang-questions] behavior of lists:append/1
Dmitry Belyaev
be.dmitry@REDACTED
Mon Sep 16 00:43:31 CEST 2019
Every additional check further reduces performance and some of us are concerned about it.
If you need correctness checks try to use static analysis tools like dialyzer/gradualizer, that way you catch the bug, we don't have reduced performance.
On 16 September 2019 4:02:25 am AEST, Karlo Kuna <kuna.prime@REDACTED> wrote:
>Michal,
>i really prefer crashing than garbage in, garbage out policy.
>also it would be nice if someone from OTP team confirms if stdlib has
>"garbage in garbage out" policy. i can certainly see benefits of it but
>in
>this case fix is easy and small.
>
>On Sun, Sep 15, 2019 at 7:54 PM Michał Muskała <michal@REDACTED>
>wrote:
>
>> My understanding is that for most functions in the Erlang standard
>> library, if you don't uphold the contract the documentation specifies
>the
>> function can crash, but it could also return whatever - in short
>"garbage
>> in, garbage out" applies.
>>
>> Michał.
>> On 15 Sep 2019, 18:45 +0100, Karlo Kuna <kuna.prime@REDACTED>,
>wrote:
>>
>> Hello,
>>
>> i have found surprising behavior of function lists:append/1:
>>
>> spec and documentation are in a agreement that this function should
>> accept lists of lists ( [List] ) ,
>> and return list of T ( [T] ), however when we use function like:
>>
>> lists:append([a]) %wrong input parameter
>> one gets:
>> a % wrong type of a return
>>
>> implementation assumes correct type:
>>
>> append([E]) -> E; % E is not checked for type
>> append([H|T]) -> H ++ append(T);
>> append([]) -> [].
>>
>> simple solution could be:
>>
>> lists:append([E]) when is_list(E) -> E
>>
>> am i missing something?
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
--
Kind regards,
Dmitry Belyaev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190916/73c4fd16/attachment.htm>
More information about the erlang-questions
mailing list