[Tutor] Why lambda could be considered evil

alan.gauld@bt.com alan.gauld@bt.com
Wed, 28 Aug 2002 18:24:35 +0100


> You could also add that list comprehensions come from 
> something called Haskell, and generators from Icon, 

> major difference between classes, generators, and list 
> comprehensions on the one hand and lambda, print >> file, 
> and print "Funny %s characters" % 

lambda should be in the first category because it is the 
correct natural name(albeit one that is not in general use) 
for what's being done. The other features are borrowed syntax 
and I agree they are not immediaely intuitive. OTOH look 
at COBOL which takes natural language to the other extreme:

X = X PLUS 1

instead of

X = X + 1

> while lambda and the two prints retain their "native" 
> we-use-special-characters syntax. 

lambda uses plain english spelling of a greek letter. Much 
worse if we had to use the actual lambda character in a 
funny font - as in Z notation for example! eek!

lambda is the common term for what it does, it just happens 
that lambda calculus is not a widely studied topic!

> that Haskell list comprehension terms such as 
> 
> [y | y <- xs, y < x]
> 
> are turned into something like this in Python: 
> 
> [y for y in xs if y < x]

Yes but List Comprehension is the natural term there not the 
syntax of Haskell. Haskell is one of many FP languages 
(albeit one of the best IMHO)

> print >> file, 'Print me'    could have been   
> print to file, 'Print me'     or even better
> print 'Print me' to file 

Yup!

> > Or studying lambda calculus!
> 
> Well, I'm not sure if the majority of Python users have 
> actually done that, 

I'm absolutely sure they won't have.

> I dimly remember having had calculus in school 

Different beast entirely.

> I think this discussion can be reduced to one question: Is Python, or 
> rather, Python's syntax, geared more towards computer science 
> people with a strong background in various computer languages or
> more at what I would call the educated computer user 

The answer is both, thats what makes it so special. There are 
lots of languages aimed at beginners but they run out of steam 
when you move beyond casual use. Python delivers easy to learn
(just ignore the wackier corners!) but then grows with you 
right up to and including OO and FP.

There are parts of Python 2.2. that I was unhappy about 
(Kirby and I had a longish mail exchange about it) but at the 
end of the day I'm free to more or less ignore those corners. 
Thats one of the really clever things about what Tim and Guido 
and the others are doing. mostly we can just keep on using 
the bits we know and the tigers can go off and play with 
the exotica.

> I would argue that so far, it is mostly geared from the 
> educated public, not specialists. 

I would disagree. It caters to both. Python has a lot of 
subtelty built in that weans newbies into doing things 
that CS departments spend ages teaching by making it 
part of the language. Python programmers learn to use 
indentation, doc strings, class browsers(dir (class)) 
and other features that students ion other languages 
sometimes never really 'get'. Almost everything in Python 
is true to CS principles while at the same time being 
as easy as it can be.

lambda is in the same category, its there and is as 
easy as I've seen it anywhere but at the same time it
does what CS expects it to do.

> "real" division. If that is in fact so, then 
> lambda and the two print forms mentioned above 

Well I was guilty of that till Mr Peters pointed out that 
many respected CS languages take that same approach and 
in fact the C variant was probably the deviant. CS doesn't 
insist in integer divisioon that was a C language thing...

lambdas are a branch of math just like complex numbers. I'd 
suggest most Python newbies don't know much about imaginary 
numbers either but having them in the language is great 
for those that do.

If you don't like lambda don't use it. If it suddenly 
looks useful do use it. If you ever get round to reading 
up on lambda calculus then great, you can use python 
to play games without having to learn Lisp or Haskell...

Alan g.