[erlang-questions] behavior of lists:append/1
Mon Sep 16 15:53:57 CEST 2019
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
append(Xs, Ys) when is_list(Ys) -> combine(Xs,Ys).
combine([X | Xs], Ys) -> [X | combine(Xs, Ys)];
combine(, Ys) -> Ys.
> I will say that I've been using languages in the Lisp family for
> a little over 40 years, and this has been the very *least* of my
The whole issue boils down to the above. I can see some trivial merit in
doing a type check over Ys at the outset (since we'll crash on bad Xs in
the actual procedure) but this business of moving to the last element to
check whether the list is properly formed is both insane and almost
certainly a legacy code killer, as there are a handful of systems out
there that depend on being able to manipulate improper lists for
I didn't follow this thread closely, but I'm surprised I didn't see
doing a single type check on entry as a possibility. What issues would
make this a bad idea?
More information about the erlang-questions