Re: Is this a good use for lambda

2004-12-22 Thread Terry Reedy
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Although if you genuinely prefer a functional programming style, > I'd go with Terry's answer rather than mine. The 'iterative' version can also be written recursively, which to most is functional. For me, the import

Re: Is this a good use for lambda

2004-12-22 Thread Nick Coghlan
Jeff Shannon wrote: Er, not as far as I can tell the 2.4 feature was what wouldn't work consistently; the corrected version, using list() and reverse(), doesn't look like it has anything that'll be a problem in my 2.2 installation, and probably not in 2.1 What he said :) Although if yo

Re: Is this a good use for lambda

2004-12-21 Thread Terry Reedy
"Alan G Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I need a clarification of the argument. > Are the opponents saying that I should not be able to: If you define 'opponent to lambda' as one who thinks such, then sure ;-). > def compose(list_of_functions): return reduce(

Re: Is this a good use for lambda

2004-12-21 Thread Jeff Shannon
Alan G Isaac wrote: So as I understand it, so far the "best" proposal for a replacement of my function-composition function uses a (compatibility reducing) Python 2.4 feature that Nick suggests will end up on "Gotcha" lists. Er, not as far as I can tell the 2.4 feature was what wouldn't wor

Re: Is this a good use for lambda

2004-12-21 Thread Alan G Isaac
So as I understand it, so far the "best" proposal for a replacement of my function-composition function uses a (compatibility reducing) Python 2.4 feature that Nick suggests will end up on "Gotcha" lists. Hmmm: lambda is looking pretty good, I'd say. The readability issue is valid, of course. Bu

Re: Is this a good use for lambda

2004-12-21 Thread Nick Coghlan
Steven Bethard wrote: Nick Coghlan wrote: def compose(list_of_functions): application_order = reversed(list_of_functions) def composed(x): for f in application_order: x = f(x) return x return composed so you either need to call reversed each time in 'composed' or copy the list

Re: Is this a good use for lambda

2004-12-21 Thread Steven Bethard
Nick Coghlan wrote: def compose(list_of_functions): application_order = reversed(list_of_functions) def composed(x): for f in application_order: x = f(x) return x return composed reversed returns an iterator to the list in reverse order, not a copy of the list: >>> lst = range

Re: Is this a good use for lambda

2004-12-21 Thread Nick Coghlan
Alan G Isaac wrote: I need a clarification of the argument. Are the opponents saying that I should not be able to: def compose(list_of_functions): return reduce(lambda f, g: lambda x: f(g(x)), list_of_functions) As things stand, I can live with lambda. However, if something can't be said in a sing

Re: Is this a good use for lambda

2004-12-21 Thread Roel Schroeven
Replying to myself, with a simpler version: Roel Schroeven wrote: Alan G Isaac wrote: def compose(list_of_functions): return reduce(lambda f, g: lambda x: f(g(x)), list_of_functions) def compose(list_of_functions): def compose2(f, g): def func(x): return f(g(x)) retu

Re: Is this a good use for lambda

2004-12-21 Thread Roel Schroeven
Alan G Isaac wrote: I need a clarification of the argument. Are the opponents saying that I should not be able to: def compose(list_of_functions): return reduce(lambda f, g: lambda x: f(g(x)), list_of_functions) Personally, I think something like this is a place where lambdas are probably better t

Re: Is this a good use for lambda

2004-12-20 Thread Fredrik Lundh
Alan G Isaac wrote: > Are the opponents saying that I should not be able to: > > def compose(list_of_functions): return reduce(lambda f, g: lambda x: > f(g(x)), list_of_functions) > > In a nutshell: why? I was about to reply, but I couldn't figure out what the piece of code does in the allotted t

Re: Is this a good use for lambda

2004-12-20 Thread Alan G Isaac
I need a clarification of the argument. Are the opponents saying that I should not be able to: def compose(list_of_functions): return reduce(lambda f, g: lambda x: f(g(x)), list_of_functions) In a nutshell: why? And may I see the proposed "better" replacement for function composition. Thanks, Al

Re: Is this a good use for lambda

2004-12-20 Thread Fredrik Lundh
Simo Melenius wrote: >> use something short, like "f". hopefully, a single character won't overload >> your brain. > > I've heard some brain can tackle even Java's overly verbose syntax I find that hard to believe. Are you sure they're not relying on eclipse, or some other body part? > Like s

Re: Is this a good use for lambda

2004-12-20 Thread Fredrik Lundh
> I just found it amusing that somenone like Frederik Lundh, who has > written xml stuff like ElementTree, uses something that reminds of an old > HTML tag as a sig. it's a perfectly valid XML end tag. locating the start tag is left as an exercise... -- http://mail.python.org/mailman/l

Re: Is this a good use for lambda

2004-12-20 Thread Max M
Steve Holden wrote: Max M wrote: Isn't it about time you became xml avare, and changed that to: Yeah, but give the guy a break, we've all made feeble attempts at humor from time to time. Hey, what's wrong with a little nørd humor... I just found it amusing that somenone like Frederik Lundh, who h

Re: Is this a good use for lambda

2004-12-20 Thread Simo Melenius
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > Simo Melenius wrote: > > Sure, but mental pollution counts too IMO. What you write and what you > > read must go through your brain, including dummy variables. And next > > you start thinking how to "hide" it from your own mind (e.g. naming it > > "_my

Re: Is this a good use for lambda

2004-12-20 Thread Steve Holden
Michael Hoffman wrote: Max M wrote: Isn't it about time you became xml avare, and changed that to: That makes no sense. Yeah, but give the guy a break, we've all made feeble attempts at humor from time to time. You realize, I suppose, that it's a reference to the fact that XHTML uses lower-case

Re: Is this a good use for lambda

2004-12-20 Thread Michael Hoffman
Max M wrote: Isn't it about time you became xml avare, and changed that to: That makes no sense. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list

RE: Is this a good use for lambda

2004-12-20 Thread Duncan Booth
Walter S. Leipold wrote: > I think that Charlie's point is that, when you use "def ", you have > polluting your namespace. The whole program becomes harder to > understand because you can't ignore anywhere, even if it was only > ever intended to be used in one place. It's a good point, and reas

Re: Is this a good use for lambda

2004-12-20 Thread Max M
The entity Fredrik Lundh wrote: Isn't it about time you became xml avare, and changed that to: ? -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a good use for lambda

2004-12-19 Thread Fredrik Lundh
Bengt Richter wrote: >>Ahem. If you name the function, you can reuse the name (or just forget about >>it) >>as soon as you've used the function object. >> >>If you don't want to reuse the name because you might want to reuse the >>function >>object, you have to name it anyway. >> > Are you forg

Re: Is this a good use for lambda

2004-12-19 Thread Bengt Richter
On Sun, 19 Dec 2004 20:59:43 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Walter S. Leipold wrote: > >> I think that Charlie's point is that, when you use "def ", you have >> polluting your namespace. The whole program becomes harder to >> understand because you can't ignore anywhere, eve

Re: Is this a good use for lambda

2004-12-19 Thread Michael Sparks
On Mon, 20 Dec 2004, Fredrik Lundh wrote: > Simo Melenius wrote: > > >> Ahem. If you name the function, you can reuse the name (or just > >> forget about it) as soon as you've used the function object. > > > > Sure, but mental pollution counts too IMO. What you write and what you > > read must go t

Re: Is this a good use for lambda

2004-12-19 Thread Fredrik Lundh
Simo Melenius wrote: >> Ahem. If you name the function, you can reuse the name (or just >> forget about it) as soon as you've used the function object. > > Sure, but mental pollution counts too IMO. What you write and what you > read must go through your brain, including dummy variables. And next

Re: Is this a good use for lambda

2004-12-19 Thread Steven Bethard
Simo Melenius wrote: Now, if lambda was more than an expr, dumping "lambda" keyword would be a convenient idea -- unnecessary keywords can make the language less clear in some cases. One could do with Python's plain and simple "def", like this: filter (def (x): x*2, myseq) (Disclaimer: Without thin

Re: Is this a good use for lambda

2004-12-19 Thread Simo Melenius
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > Walter S. Leipold wrote: > > I think that Charlie's point is that, when you use "def ", > > you have polluting your namespace. The whole program > > becomes harder to understand because you can't ignore > > anywhere, even if it was only ever intended

Re: Is this a good use for lambda

2004-12-19 Thread Steven Bethard
Walter S. Leipold wrote: I've used lambda from time to time, but only socially, and I can quit any time I want... +1 QOTW Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a good use for lambda

2004-12-19 Thread Fredrik Lundh
Walter S. Leipold wrote: > I think that Charlie's point is that, when you use "def ", you have > polluting your namespace. The whole program becomes harder to > understand because you can't ignore anywhere, even if it was only > ever intended to be used in one place. Ahem. If you name the fun

RE: Is this a good use for lambda

2004-12-19 Thread Walter S. Leipold
Steven Bethard wrote: > Charlie Taylor wrote: >>I have tried using named functions instead of using lambda functions, >>however, I always end up with a convoluted, hard to follow mess. > ... > Well, I think the jury could still be out on which version is more > readable, but I don't understand the

Re: Is this a good use for lambda

2004-12-18 Thread Michael Hoffman
Charlie Taylor wrote: flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) def _flow_func(x): return 2.0 * pi * d(x) * v(x) * sin(a(x)) flow = integrate(_flow_func, xBeg, xEnd) root = findRoot(xBeg, xEnd, lambda x: y2+ lp*(x-x2) -wallFunc( x )[0], tolerance=1.0E-15) d

Re: Is this a good use for lambda

2004-12-18 Thread Terry Reedy
"Charlie Taylor" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > I find that I use lambda functions mainly for callbacks to things like > integration or root finding routines as follows. > > flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) > > root = findRoot

Re: Is this a good use for lambda

2004-12-17 Thread Jeff Shannon
Charlie Taylor wrote: root = findRoot(xBeg, xEnd, lambda x: y2+ lp*(x-x2) -wallFunc( x )[0], tolerance=1.0E-15) Um, so which parts of this are the actual lambda?? Just from reading that, it's hard to be sure. My mind keeps wanting to break at 'lambda x: y2 + lp*(x-x2)', but when I sto

Re: Is this a good use for lambda

2004-12-17 Thread Steven Bethard
Harlin Seritt wrote: Charlie Taylor wrote: I find that I use lambda functions mainly for callbacks to things like integration or root finding routines as follows. flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) root = findRoot(xBeg, xEnd, lambda x: y2+ lp*(x-x2) -wallF

Re: Is this a good use for lambda

2004-12-17 Thread Stephen Thorne
On Fri, 17 Dec 2004 15:58:09 -0800, Charlie Taylor <[EMAIL PROTECTED]> wrote: > > I find that I use lambda functions mainly for callbacks to things like > integration or root finding routines as follows. > > flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) > > root = findRo

Re: Is this a good use for lambda

2004-12-17 Thread Harlin Seritt
Charlie Taylor wrote: > > I find that I use lambda functions mainly for callbacks to things like > integration or root finding routines as follows. > > flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) > > root = findRoot(xBeg, xEnd, >lambda x: y2+ lp*(x-x2) -wallFu

Re: Is this a good use for lambda

2004-12-17 Thread Jp Calderone
On Fri, 17 Dec 2004 15:58:09 -0800, Charlie Taylor <[EMAIL PROTECTED]> wrote: > > I find that I use lambda functions mainly for callbacks to things like > integration or root finding routines as follows. > > flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) > > root = find