Buscar en Mind w/o Soul

viernes, marzo 14, 2008

Python vs Ruby: los closures incompletos

Los closures de Python no guardan el contexto original, crean una copia, así que no son iguales a los de Lisp. Los de Ruby, sí.

Ivan: Closures in Python (part 2)
Limitation of lambda

In the non-list comprehension examples, the "lambda" keyword for creating a closure in Python can only be used with an expression, not any arbitrary code. This happens to be OK for the examples in Martin's article, but consider something just a tiny bit more complicated:

Let's say you wanted to do:

map(lambda each: if each.isManager: each.salary = 2000, employees)

You can't. "if each.isManager: each.salary = 2000" isn't an expression.

No hay comentarios: