List append buglet...?

Mickael Remond mickael.remond@REDACTED
Mon Feb 5 11:14:22 CET 2001

On Mon, 5 Feb 2001, Andrew Shelton wrote:
> Greetings,
> Well, if it wasn't a bug it certainly was suprising behaviour. It also
> seems to violate the stdlib documentation. Since it's such a basic 
> operation it took me a while to track down what was going on...
> Erlang (BEAM) emulator version 4.9.1 [source]
> Eshell V4.9.1  (abort with ^G)
> 1> []++[1].
> [1]
> 2> []++{1}.
> {1}
> 3> 
> At least it's simple to demonstrate. Apologies if this has been
> fixed in the most curent.

I do not know what you were expected exactly, but the behaviour of the list
appending function is still the same in the last Erlang version (

What is funny is that the function cannot be reversed:
8> {1}++[].

=ERROR REPORT==== 5-Feb-2001::10:59:22 ===
Error in process <0.34.0> with exit value: {badarg,[{erlang,append,[{1},[]]},{erl_eval,eval_op,3},{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}
** exited: {badarg,[{erlang,append,[{1},[]]},
                    {shell,eval_loop,2}]} **

Moreover, I discovered that the "++" operator is used in the lists:append/2
function. I thought that ++ was a syntaxic sugar for the lists:append
function, but this does not seem to be the case.
Thus, you get exactly the same result in the list append function.

Apparently, only the first argument is check to see if this is a list. The
second one is not checked and can be anything.

If the first element is an empty list, so the second element is directly sent
back. Thus, the lists:append function does not necessarily send back a list but
can return anything.

So, I think you are right, this is not consistent with the documentation, and
I think this is not the wanted behaviour.

   Mickaël Rémond                    tel :      (33)
   Chef de projet                    mob :      (33)
   15 - 17 avenue de Ségur           e-mail :   mickael.remond@REDACTED
      75007 - Paris                  web :

More information about the erlang-questions mailing list