optimization of list comprehensions

Peter Lund erlang@REDACTED
Mon Feb 27 10:59:19 CET 2006


I confess also I like to use list comprehensions instead of the uglier 
lists:foreach.

To make it clear that you are not at all interested of the return value, 
I propose that people do it this way:

   _ = [f(X) || X<-List],
   _ = [g(X) || X<-List2],

Clearer than this it hardly can get...

/Peter

Ulf Wiger (AL/EAB) wrote:

>I've seen many examples of how people use
>list comprehensions as a form of beautified
>lists:foreach() - that is, they don't care
>about the return value of the comprehension.
>
>I hesitate to say that it's bad practice,
>even though one will build a potentially
>large list unnecessarily, since it's 
>actually looks a lot nicer than using 
>lists:foreach().
>
>Question: would it be in some way hideous
>to introduce an optimization where such
>list comprehensions do everything except
>actually build the list? Then they could
>execute in constant space.
>
>/Ulf W
>
>  
>




More information about the erlang-questions mailing list