[erlang-questions] Wrong advertised spec of lists:append/2
Kostis Sagonas
kostis@REDACTED
Thu Mar 28 14:55:03 CET 2013
On 03/28/2013 03:36 PM, Pierre Fenoll wrote:
> 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]?
You are reading specs (and the documentation) in the wrong direction.
In library code, the spec for a function tells you two things:
- you are supposed to call a function with terms of the given types in
the arguments, and
- if you issue such a call with the "expected" types, you can also
expect that the type of the return value of the function is the one
mentioned in the spec.
The spec says nothing about what happens when you issue a call with the
"unexpected" arguments (as in your example). In most cases you will get
a bad match exception, but the implementation of the function may be
more lenient than its published specification.
Kostis
More information about the erlang-questions
mailing list