[erlang-questions] behavior of lists:append/1
Tue Sep 17 16:25:11 CEST 2019
On 2019/09/17 22:13, Raimo Niskanen wrote:
> 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:
>> append(Xs, Ys) when is_list(Ys) -> combine(Xs,Ys).
>> combine([X | Xs], Ys) -> [X | combine(Xs, Ys)];
>> combine(, Ys) -> Ys.
> lists:append/2 can be used and *is* used by existing code to construct
> improper lists. It would break backwards compatibility.
The accept/2 -> combine/2 combination accepts improper lists just fine.
That was the whole point and I addressed the detail of actually
*needing* to accept improper lists for the sake of legacy code. It only
checks whether the 'Ys' is a list *at all* before proceeding.
The beaten horse is now absolutely craven for some abuse.
More information about the erlang-questions