[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: map/filter/reduce/lambda opinions and background unscientific
From: Steven Bethard <steven.bethard () gmail ! com>
Date: 2005-07-06 23:17:45
Message-ID: admdnV08AI8E-1HfRVn-hQ () comcast ! com
[Download RAW message or body]
Daniel Schüle wrote:
> Removing lamdba would be reduce readability of Python, I think here
> for examble of code like
>
> class App:
> ....
> ....
> def drawLines(self, event):
> from random import randint
> r = lambda : randint(1, 100)
> self.canvas.create_line(r(), r(), r(), r())
>
> defining one extra function would only confuse and
But you just did define one extra function!!
If you're really afraid of two lines, write it as:
def r(): randint(1, 100)
This is definitely a bad case for an anonymous function because it's not
anonymous! You give it a name, r.
> and what about creating one liner factories like
> from math import log10
> log = lambda basis: lambda x: log10(x) / log10(basis)
> log2 = log(2)
> log2(2**10) -> 10.0
This is slightly better, because at least one of your functions really
is anonymous. I'm not really sure I'm convinced that it's any better
than this though:
def log(base):
def log_in_base(x):
return log10(x)/log10(base)
return log_in_base
because when I first read the code, I didn't catch the second, nested
lambda. Of course, with a syntax-highlighting editor, I probably would
have.
Again though, to fix your abuse of anonymous function syntax for
non-anonymous functions, you should write this as:
def log(basis):
return lambda x: log10(x) / log10(basis)
Or if you're afraid of multiple lines:
def log(basis): return lambda x: log10(x) / log10(basis)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic