[erlang-questions] List pipe syntax
Mon Dec 18 13:14:36 CET 2006
I have a question about the pipe syntax when building lists.
According to the Erlang reference a list is either the empty list  or
consists of a head and a tail which is also a list. [Head|Tail].
I've noticed that you can do some weird "list"-building using the pipe
[1|] is obviously a list according to the definition since  is a list.
But what about [1|2]??. This shouldn't evaluate to a list since 2 isn't a
list. I checked it with erlang:is_list([1|2]) which returned true. You can
also use the matching [H|T] = [1|2] where H is bound to 1 and T is bound
to 2. [1|2] == [1,2] returns false.
I figured that [1|2] was evaluated to a list of length 1 with the strange
element 1|2, but erlang:length([1|2]) exits with a badarg.
It's definitely not a list, but what is it then and why does
erlang:is_list return true?
More information about the erlang-questions