Is it a list ?

Marc Ernst Eddy van Woerkom Marc.Vanwoerkom@REDACTED
Thu Jul 10 22:41:32 CEST 2003


>   > 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.


> Instead, it's common in Lispy
>   languages to define a 'list' as "either a cons or null/[]", and to
>   treat the "properly" null-terminated list as a different, informal
>   type.

In other words: historic tradition


>   [1|2] takes up less memory (two numbers, one cons cell) than [1,2]
>   (really [1|[2|[]]] - two numbers, two cons cells, and [].) {1,2} also
>   uses more space than [1|2] since it needs to record the length.
>
>   The 'digraph' module of stdlib represents edges as ['$e'|UniqueNumber]
>   for this memory efficiency.

I don't like that. What is the sense to use a rather slow but sophisticated 
high level language (thus hope for correctness) like Erlang and then 
to resort to optimaztion tricks? 


>   These "improper" lists are also an excellent way to break other
>   languages' implementations of the Erlang external term format

So Erlang can play rude, as well, eh? :)

Regards,
Marc








More information about the erlang-questions mailing list