using lambda to print everything in a list

Steven D. Majewski sdm7g at Virginia.EDU
Fri Apr 27 12:09:32 EDT 2001


On Fri, 27 Apr 2001, Alex Martelli wrote:

> "Jeff Shipman" <shippy at nmt.edu> wrote in message
> news:3AE8BCA9.386446CD at nmt.edu...
> > I've started to discover the real handiness with
> > lambda expressions in python. I would like to
> 
> Maybe one day you'll explain it to me as well...?
> 
> My personal impression is that lambda is a (minor)
> nuisance.  Naming the code fragment that you want
> to pass to some other function, by making it a
> nested function, seems clearer & handier to me.
> 

OK Alex, I'll volunteer an explaination:

Lambda is typically used for temporary, throw-away functions in
expressions. 

 You could say exactly the same thing about anonymous (unnamed,
temporary) values in expressions. Requiring every value to be
named wouldn't at all change the capabilities of a language. 
You can't do anything new with anonymous expressions than you
can't do without them. But without them, you would have to use
a lot of temp variable names:

Would you really find:

	tmp1 = a+b
	tmp2 = c+d
	tmp3 = tmp1 * tmp2
	final = tmp3 / count

to be more clean than:
	final = (a+b)*(c+d)/count

just because every thow away value was given a name ? 

The former reads more like a symbolic macro assembler than 
a high level computer language. 

Sometimes it's more clear to leave some things unnamed. 
( Most human languages have pronouns, don't they ? 
  Since everyone so enjoyed the language side-thread: 
   are there any pronoun-free languages ? ) 



It's exactly the same case with anonymous functional expressions.

It's a conveniece. 

The only difference is that almost all programs use a lot more 
operator composition than functional composition -- so using a language
without anonymous temp values in expressions would be about 100x
more onerous than using one missing anonymous functional expressions. 

But it would be annoying for exactly the same reasons. 

That 100x estimate has a pretty large variance due to both personal 
programming style and problem domains. Maybe for you it's closer
to 1000x, and for me closer to 10x. 


-- Steve Majewski






More information about the Python-list mailing list