[Tutor] Text processing and functional programming?

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Aug 14 09:14:16 EDT 2003


Hi Clay,

> of pythons list expressions intoxicating, and while I agree that map
and
> filter are somewhat mnemonic, lambda feels kludgy to me,

The point about all of these functions is that they are a
staight translation of the math. If you get a book on discrete math
and read about predicate and lambda calculus you will find that
the fundamental operations include maps, filters, reductions
comprehensions and lambdas.

Software engineering folks often say the difference between
S/w engineering and traditional engineering is the lack of
a mathematical basis, however thats only half true, using
prdicate calculus etc you can go straight from a meth
expression of the problem to a software solution, just as you
can go from a meth model to an electronic circuit diagram etc.

The problem is very few people, even computing students,
study discrete math. But FP is simply a way of expressing
of discrete math more directly in code.

> ourselves in the foot there with that 'one argument' limit -- better
make a
> wrapper for inline functions."

BTW I do agree that Pythons lambda implementation is a little
flaky compared to, say Lisp, but it is mathematically sound and
theoretically complete.

> So because list comprehensions are a single construct that does
> the job of several functions,

comprehensions do a single job, that of building lists.
Its coincidental that you can use a comprehension to apply
a filter etc. To be pedantic :-)

> guide to FP that explains them in terms of list comprehensions?

I doubt it but you may be better looking through a math book instead.
Truth to tell it was only when I saw the math behind it that FP
started to make sense to me. I can recommend the old, but still
valuable:

Logic, Algebra and Databases by
Peter Gray

if you can get hold of it.
You only ned to read the first 3 chapters to understand FP, but
if you also want the mathematical basis behind languages like
Prolog and SQL then go ahead and read the rest too.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list