[erlang-questions] Wrong advertised spec of lists:append/2
ok@REDACTED
ok@REDACTED
Sat Mar 30 10:55:00 CET 2013
> Hi,
>
> As per the doc, the spec of lists:append/2 is ([term()], [term()]) ->
> [term()].
>
> However, a = lists:append([], a).
>
> Shouldn't it return [a]?
Since you violated the precondition (the second argument is not
a list of terms) you have no right to expect the postcondition
(that the result is a list) to be true.
Besides, why *should* the result be [a] rather than [] or
[[[[a]]]] or [97] or anything else?
Given that the definition that applies to _all_ cases
is (an accelerated version of)
append([X|Xs], Ys) -> [X|append(Xs, Ys)];
append([], Ys) -> Ys.
how *could* the result be [a]?
More information about the erlang-questions
mailing list