[erlang-questions] What's this mean:[1|1]?It's it a bug?

Lukas Larsson lukas@REDACTED
Wed Jul 3 14:34:47 CEST 2013

On Wed, Jul 3, 2013 at 12:09 PM, Ivan Uemlianin <ivan@REDACTED> wrote:

> [1|1] is an "improper list", in other words, a list that doesn't end with
> an empty list [].  They're valid, but not terribly safe:
>   1> is_list([1|1]).
>   true
>   2> length([1|1]).
>   ** exception error: bad argument
>        in function  length/1
>           called as length([1|1])
> I don't know if there's any use for them.

It can be used to save two words of memory as [1|1] is two words but [1,1]
is four words. So if you are developing a highly optimized data structure
(like dict for instance) it is useful. Most people will however not need

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130703/2a6ef05e/attachment.htm>

More information about the erlang-questions mailing list