A replacement for lambda
D H
no at spam
Sat Jul 30 04:08:22 EDT 2005
Mike Meyer wrote:
> Rewriting a canonical abuse of lambda in this idiom gives:
>
> myfunc = def @(*args):
> return sum(x + 1 for x in args)
Nice proposal. Technically you don't need the @ there, it is
superfluous. But then again so is the colon, so whatever floats your boat.
> class Spam(object):
> myprop = property(fget = def @(self):
> return self._properties['myprop']
> ,
> fset = def @(self, value):
> self._properties['myprop'] = value
> ,
> fdel = def @(self)
> del self._properties['myprop']
> ,
> doc = "Just an example")
I think the anonymous lambdas need to be outside the parentheses to be
parsable. Maybe like this:
class Spam(object):
myprop = property(fget, fset, fdel, doc="just an example"):
where fget = def (self):
.........
where fset = def (self):
.........
where fdel = def (self):
...........
As you can see, it doesn't save much over the traditional way since you
have to name the "anonymous" lambdas anyway.
More information about the Python-list
mailing list