optimization of list comprehensions

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Tue Mar 7 23:02:18 CET 2006

Richard O'Keefe wrote: 

> 	  secondly; for whatever reason normal
>       industry programmers(*)
>       will rarely if ever use lists:fold* (or
>       indeed anything that involves funs).
>       they didn't use lists:map or lists:foreach 
>       either, but they do use list comprehensions.
> If you have evidence to back this up, it's publishable.
> Please publish it.  Some sort of survey analysing what kind 
> of programmers use what kind of language features would be 
> most illuminating.

Hmm... I just posted the following on 
In our production code, I just did a search on calls
to the 'lists' module (a collection of polymorphic
iterator functions and other generic operations on lists)
and the pattern 'fun(', signifying the definition of a 
higher-order function in Erlang. I focused on one 
subsystem - one that has fairly recently written code.

In 154K lines of code, a simple 'grep' revealed 937 calls
(6%) to 'lists:...' and 452 (3%) declarations of higher-
order functions(*). Perhaps even more interesting, there
were 198 instances (1.3%) of list comprehensions (only
200 generators, though, so nearly all lcs are simple).

(*) Granted, many calls to the lists module will 
invclude a fun() (e.g. foldl, map, foreach, ...)

I think it's safe to say that even "average" industrial 
programmers rather quickly learn to exploit the virtues
of higher-order functions and iterators.

Ulf W

More information about the erlang-questions mailing list