[Haskell-cafe] Python?

Daniel Carrera dcarrera at digitaldistribution.com
Wed May 11 02:11:56 EDT 2005


Quinn Dunkan wrote:

> Python has first class functions and lexical scoping, and encourages
> higher-order functions, though to a much lesser degree than a real
> functional language.

I was surprised to hear about first class functions and higher order 
functions. So I googled for a bit, and I found something neat:

---<snip>---
# Python implementation of Common Lisp's remove_if
def remove_if(predicate, lst):
     return [elem for elem in lst if not predicate(elem)]

print remove_if(lambda x:x % 2, [1,2,3,4,5,6,7,8])
---<snip>---

This is so cool. So there we have a higher order function, passing a 
funtion as an argument, and even lambda notation. Neat.


> It is very natural to
> write in a somewhat functional style, especially in regards to
> sequence processing: higher order functions and listcomps provide the
> processing and its built in generators and iterator protocol provide
> some of the benefits of laziness.

Hhhmmm.. I guess the above is also an example of that.

[snip: lots of very interesting info I didn't know about]

Thank you for all the information. I learned a lot today. I had no idea 
that Python had these features.

Cheers,
Daniel.


More information about the Haskell-Cafe mailing list