functional programming

Quinn Dunkan quinn at
Mon Feb 21 14:49:50 EST 2000

On Fri, 18 Feb 2000 17:24:10 -0500 (EST), Michal Wallace (sabren)
<sabren at> wrote:
>Hey All,
>  That Software Development Magazine article had a sidebar which
>mentions that python supports functional programming. I know what
>functional programming IS, and I can see how python supports it, but
>I'm wondering if anyone has any examples of actually putting this
>to use?

def f(x):
    return x * 2

j = f(5)

'Functional programming' is simply the application of 'pure' (no side-effects)
functions.  The difference (I can see) between 'functional' and 'not
functional' languages is that functional languages stop there, and give you a
whole bunch of shortcuts to ways to make it easier to stand it (higher-order
functions, monads, tail recursion, etc.).
'not functional's give you extras like mutable objects, control structures
(loops, if then).

Perhaps this is simply the magazine's confused way of saying that functions /
methods are first-class in python.  Ecce codo:

lst = map(f, range(10))
lst = map(lambda x: x * 2, range(10))

I use map, filter and reduce occaisionally, but often it's easier to write a
loop in python.  If list comprehensions make it in, I'll use them all the
time, replacing all those hard-to-read loops with easy [x for x in ...].

More information about the Python-list mailing list