[erlang-questions] behavior of lists:append/1

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue Sep 17 15:13:11 CEST 2019


On Mon, Sep 16, 2019 at 10:53:57PM +0900, zxq9 wrote:
> On 2019/09/16 11:49, Richard O'Keefe wrote:
> > The fact that L is a well-formed list is verified N times,
> > for a total cost O(N * |L|).  But with the current definition,
> > the cost is O(N), independent of |L|.
> 
> Hm... just to beat a dead horse...I suppose we could get away with a 
> single check:
> 
>    -export([append/2]).
> 
>    append(Xs, Ys) when is_list(Ys) -> combine(Xs,Ys).
> 
>    combine([X | Xs], Ys) -> [X | combine(Xs, Ys)];
>    combine([],       Ys) -> Ys.

No.

lists:append/2 can be used and *is* used by existing code to construct
improper lists.  It would break backwards compatibility.
-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list