[erlang-questions] Wrong advertised spec of lists:append/2
Pierre Fenoll
pierrefenoll@REDACTED
Sat Mar 30 13:47:50 CET 2013
Well, as Norton said, I was just expecting a badarg to get thrown.
Here nothing gets thrown thus a bug gets harder to find…
On 30 March 2013 11:10, <ok@REDACTED> wrote:
> >> 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) ?
>
> Why?
> 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.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130330/c64d5eb9/attachment.htm>
More information about the erlang-questions
mailing list