[erlang-questions] Wrong advertised spec of lists:append/2
Sat Mar 30 14:48:52 CET 2013
Doesn't Dialyzer complain if it discover you don't give lists:append/2 two lists? That's the whole point of specs, right?
Le 30 mars 2013 à 13:47, Pierre Fenoll a écrit :
> 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) ?
> 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.
> erlang-questions mailing list
More information about the erlang-questions