[Tutor] Text processing and functional programming?

A.M. Kuchling amk at asti-usa.com
Thu Aug 14 14:07:02 EDT 2003


> I believe Alan when he says the studies find that FP leads to more
> performant code, but I still don't really understand why you would chose a
> map/filter/lambda construction over a list comprehension, or v-v.

The only case when I use map/filter these days is when there's already
some built-in function that does the job.  Compare:

	L = map(int, L)
	L = [int(s) for s in L]

I find the first formulation preferable.  There aren't many built-in
functions that return Booleans -- I can't think of *any* offhand -- so
I never use filter(), only map().

> Are there times when you can do something with one of those constructs but
> not the other?

No; map/filter let you do exactly what list comps do.

A big reason for interest in functional programming stems is academic,
stemming from interest in proving things about programs.  Assignment
is very hard to handle in mathematical analyses of programs, and the
job of rigorously proving that a function f() implements the right
computation is made much easier if assignment is forbidden.  It's also
easier to perform transformations on a functionally-written program,
if you want to parallelize it or something.

--amk                                            (www.amk.ca)
I can hear the sound of empires toppling.
      -- The Doctor, in "The Happiness Patrol"




More information about the Tutor mailing list