Is it a list ?

Richard Carlsson richardc@REDACTED
Thu Jul 10 23:12:22 CEST 2003

----- Original Message ----- 
From: "Marc Ernst Eddy van Woerkom" <Marc.Vanwoerkom@REDACTED>
To: <luke@REDACTED>

> >   > But why is is_list([1|2]) true?
> >
> >   Probably because a proper test would mean traversing all the way to
> >   the end, which could be expensive.
> I would prevent that by trying to make it impossible to
> create inproper lists in the first place.
> The question is, if this would be possible.

Possible, yes (although it would break some existing code, of course)
but it would also be expensive. For each new cons cell created,
you would get a test-and-branch. It is simply much more convenient
to allow any term in the second argument, and let the users decide
how to use the cons cells - for proper lists only, or for tree-like
structures as well. In Erlang programs, you don't see non-proper
lists being used often.

Of course the 'is_list' test could have been given the more correct name
'is_nil_or_cons_cell', but when you've typed that enough times, you tend
to say "screw correctness, I want a shorter name for this thing!". And
generally you do not want to traverse the whole list for each test, so
making 'is_list' only yield true for proper lists is not a good solution


More information about the erlang-questions mailing list