[erlang-questions] behavior of lists:append/1
zxq9
zxq9@REDACTED
Thu Sep 19 08:58:19 CEST 2019
On 2019/09/19 10:33, Richard O'Keefe wrote:
> I'm sorry, but what O(1) runtime check are we talking about here?
> I don't know of any O(1) way to test "is this a proper list" in
> Erlang.
Not checking for whether something is a properly formed list (the whole
objection some have is that append/2 should be able to accept an
improper list as the second argument) but merely checking whether the
second argument is a list of any form at all.
A single is_list/1 check guarding the leading clause can do that.
The discussion has gone through:
A1: "The typespec says both arguments must be lists"
B1: "Use Dialyzer"
A2: "The check should be dynamic at runtime"
B2: "Checking for *proper* lists is too much overhead"
A3: "We should accept improper lists as a second argument"
B3: "Then is_list/2 could check the 2nd arg on entry only"
A4: "Some people use append/2 to *construct* improper lists"
B4: "Then why do we even have a typespec at all?"
My position is that B2 and A3 are valid, and B3 is a reasonable
compromise that shouldn't break legacy code. I think A4 is unreasonably
inconsistent, though, and would wonder why we're even going to have a
typespec.
-Craig
More information about the erlang-questions
mailing list