a little trap revealed (was Re: Let's Talk About Lambda Functions!)

Jeremy Bowers jerf at jerf.org
Sat Jul 27 10:34:17 EDT 2002


On Sat, 27 Jul 2002 02:11:46 -0500, Alex Martelli wrote:

> Jeremy Bowers wrote:

> Not sure why you snipped the closure solution, which looks like
> the obvious one to me once one has seen it:

Oops, sorry, too late. I ended up scrolling over it.

>> (And I'll still take the lambda form; the def statement feels wrong here.)
> 
> Guess that's what wrong with having lambda in the language: without
> adding any capability, it gives two ways to solve some problems, one
> of which feels wrong to you, the other one of which IS wrong.

Fair enough.

> Because, you see, I put a little trap in this example... and it
> seems to me that you fell right into it.

Yes and no... I never wrote a lambda myself that had a print in it. I know
you can't do that, and others had already commented on it.

I almost always use a print function of my own devising, so I _can_ use
print in a lambda. 

(That's not why I wrote that function though; I like emacs as my
coding environment, but you get all the output and error tracebacks all at
once, as a lump when you close the program, if it's a Tk program. I have
a print function that can go over the network, or to console, or to
nowhere at all.)

> Use def and avoid all of this silly self-imposed useless work.

I already don't use "print" so perhaps that part of the reason it doesn't
bother me. (Note I'm not proposing this is a solution everyone should
seek, just that it may explain my ambivilence on the issue.)



More information about the Python-list mailing list