Proper or well formed Lists

Tony Rogvall tony@REDACTED
Sat Dec 16 00:16:21 CET 2000


Robert Virding wrote:

> Francesco Cesarini <cesarini@REDACTED> writes:
> >A well formed list follows the definition List = [Term|List] or []. Why
> >where non proper (or well formed) lists (List = [Term|Term] ex:
> >[hello|world]) allowed in the language in the first place?
> >
> >I am having a hard time seeing the need or intent with non well formed
> >lists, other than a simplifying run-time evaluations and possibly the
> >parsing. Wouldn't it have been better to have expressions not evaluating
> >to a well formed list result in a run time error?
>
> The reason is mainly hereditary, the high-level languages we were used
> to when we started developing Erlang were Lisp and Prolog and both these
> languages allow this.  Also the early versions of Erlang were Prolog
> interpreters.  We did have some discussion about this but did really
> feel it important enough to warrant a change.
>
> Anyway think of the cool things you can do with it!  Also think how
> much more efficient cons is. :-)
>
>         Robert

I implemented a key-value dictionary on form [Key|Value] once :-)
It is much more memory efficient. {Key,Value} is represented with three
cells while [Key|Value]  is represented with two, and [Key,Value] needs
four cells!  (Given that Key and Value are ground)

The construct [a|b] even has a name, dotted pair (from lisp).

/Tony

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tony.vcf
Type: text/x-vcard
Size: 333 bytes
Desc: Card for Tony Rogvall
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20001216/7faf8b30/attachment.vcf>


More information about the erlang-questions mailing list