[erlang-questions] Wrong advertised spec of lists:append/2

Sat Mar 30 11:10:27 CET 2013

>> It's not a contradiction, as kostis noted specs are not complete
>> enumerations of all possible argument types.
> Well, lists:append/2 asks for a list() as a second argument. Shouldn't
> it badarg when I give it 'a', as in lists:append([], a) ?

Remember that the definition
 append([X|Xs], Ys) -> [X|append(Xs, Ys)];
 append([],     Ys) -> Ys.
is primary.  That has been around since day 1.  The spec
is a very late addition indeed which is a useful apprimation
of the original behaviour, and says *NOTHING* about what
will happen if you violate the precondition.

This definition of append is a historic one from Lisp:
Welcome to Clozure Common Lisp Version 1.5-r13651  (DarwinX8632)!
? (append '(a b) 'c)
(A B . C)
and Scheme:
Gambit v4.4.3
> (append '(a b) 'c)
(a b . c)
It's essentially the same as what's found in Prolog:
?- append([a,b], c, Zs).
Zs = [a, b|c].

Remember, a function specification says what the result will
be *IF* the arguments have a certain form, and says *NOTHING*
about the behaviour of the function if they do not.

More information about the erlang-questions mailing list