Optimization of list comprehensions?

David Gould dg@REDACTED
Mon Feb 5 19:16:48 CET 2001

I really like list comprehensions, they seem so, declarative. I am tempted
to use them everywhere ;-)

But, what does the compiler do with them?

Does it generate better code for a list comprehension than for using

Is it able to detect when a listcomp is used for its side effects alone and
not build the result? For example, is:

 [io:format('~s~n', [Item]) | Item <- Items].

more or less effcient than:

 lists:foreach(fun(Item) -> io:format('~s~n', [Item])) end, Items).

Oh yeah, is it better or worse style?


David Gould                                                 dg@REDACTED
SuSE, Inc.,  580 2cd St. #210,  Oakland, CA 94607          510.628.3380
You left them alone in a room with a penguin?!  Mr Gates, your men are
already dead.

More information about the erlang-questions mailing list