Functional style programming in python: what will you talk about if you have an hour on this topic?
ian.g.kelly at gmail.com
Wed Jul 13 13:09:16 EDT 2011
On Wed, Jul 13, 2011 at 10:29 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> The iteration protocol and the notion of iteraables as the common data
> exchange format, with associated notions of iterators, generator functions,
> and generators, are important features of Python. Not really functional
> style, I guess.
Xah Lee's assertion to the contrary notwithstanding, it seems to me
that list comprehensions are basically functional in style. They are,
after all, equivalent to "map(f, filter(g, x))".
Iterators, on the other hand, by definition have the property that
each call to iter.next() has the side effect of changing the
iterator's state. Therefore, although they can effectively be used as
a functional building block (e.g. by masking their use with a
comprehension), the iterators themselves are not actually functional.
More information about the Python-list