[erlang-questions] behavior of lists:append/1
Richard O'Keefe
raoknz@REDACTED
Thu Sep 19 10:29:15 CEST 2019
"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."
But what the heck is the point of *that*?
Why is it important for [a] ++ c to fail
but OK for [a] ++ [b|c] to succeed?
I'm sorry, but that makes no sense to me at all.
On Thu, 19 Sep 2019 at 18:58, zxq9 <zxq9@REDACTED> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190919/e09814d8/attachment.htm>
More information about the erlang-questions
mailing list