List comprehension or lists:foldl/3 ?

Chris Pressey cpressey@REDACTED
Fri Feb 13 07:31:46 CET 2004


On Fri, 13 Feb 2004 00:56:10 -0500
Shawn Pearce <spearce@REDACTED> wrote:

> Which is the more preferred form amongst you hacker types?
> 
> 	NodeList = [...],
> 	[erlang:monitor(process, {myserv, N}) || N <- NodeList],
> 	ok
> 
> or
> 
> 	NodeList = [...],
> 	lists:foldl(
> 		fun(N, _) -> erlang:monitor(process, {myserv, N}) end,
> 		0,
> 		NodeList
> 	),
> 	ok
> 
> I'm not concerned about the speed here, as its a startup routine
> run once when the node boots.  Even for a very large cluster of
> over 200+ nodes (highly unlikely in my application) this would take
> no time either way.  This is a preferred syntax poll.
> 
> I find the LC easier to read by far.
> 
> -- 
> Shawn.

I would probably use lists:foreach/2 instead just to drive home the fact
that you're evaluating this for its side effects & don't care about the
return value.  But that's just me.

-Chris



More information about the erlang-questions mailing list