Algorithmic lists

Richard Carlsson <>
Mon Oct 16 13:32:49 CEST 2000

On Mon, 16 Oct 2000, Thomas Arts wrote:

> Ulf Wiger wrote:
> > 
> > A list could be expressed in the following manner:
> > 
> > [Head | fun(Head, F)]
> I don't really like that notation, since the tail of a list is no
> longer a list now (but a function returning a list). I find it more
> natural to return a tuple, a kind of continuation.

Yes, however, the cons cells are much more efficient in terms of memory
allocation (in current Erlang implementations), only needing 2 words where
a tuple needs three. I don't find it unreasonable to use cons cells for
certain datatype representations, when they map so naturally to "cons or
nil" as in this case. "cons cell" does not always have to imply "proper
list", although for general purpose programming cons cells should not be

> It would be nice if this could be established by a smart,
> lazy list-comprehension:
> [ X || X<-seq(1,5), condition(X) ]

I agree that it would be quite nice for Erlang to have language support
for lazy list comprehensions. As I recall, when list comprehensions were
first about to be introduced in Erlang, there was some debate about
whether they should have lazy semantics or not. However, I think that it
was correct that normal list comprehensions in Erlang should have strict

It should probably not be a problem to implement a lazy version also.

	/Richard Carlsson

Richard Carlsson ()   (This space intentionally left blank.)
E-mail: 	WWW:

More information about the erlang-questions mailing list