[Tutor] fancy list things

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Feb 6 16:59:09 EST 2004

> > Hmmm... you may want to avoid talking about lambda, then.
Concentrate on
> > what you're comfortable talking about.  I'd recommend focusing on
> Oh.  I don't mind exposing my ignorance (obviously).  It's a good
> teaching/learning technique.  And it encourages students to expose
> their ignorance.

It depends a bit on what your students are. If they are youngsters
then I'd probably avoid lambda.

But if they are adults with a smattering of math background
then teaching lambda early is a valid thing to do because it
will teach them a fundamental concept that is very important
in programming - namely that executable bits of code (in
Python's case restricted to expressions!) can be passed around
like any other kind of programming object, and the proper
name for such a chunk of code is a lambda.

It depends how much you want to teach the theory of programming
versus how to program to produce a working solution. If you
understand the concepts of lambda then it helps you build
better structured programs in some tricky situations. But
95% of the time you can live quite happily without lambda
- and in Python its never needed, just nice to have as a shortcut.

> "Python2.2's nested-scope behavior also makes it easier for
> programmers to write lambda expressions.  A lambda expression-- when
> evaluated-- produces a function, in much the same way (some named
> function) produces a function.  Many programmers use lambda
> to define callbacks for GUI applications.  In this text we have
> to focus on object-orented programming in Python, rather than on
> functional or procedural programming."
> And that is all it says.  So I'm asking here.

If you know what they are talking about its a perfectly good
explanation. But like so much of the Dietel books they only
make sense after you understand them. Which rather defeats the
object of the exercise! I often find thatchapters which I
thought were hard to understand, once I've found out how to
do it - usually from another book, when I go back to Dietel
its obvious what they meant.

> It's a cool example.  Some of my students are perl programmers.

Perl has its own equivalent to lambda (but I can't recall the
arcane syntax - its Perl it must be arcane :-) so they may well
grok lambda easily.

A final plug, my functional programming topic covers lambdas
as well as map(), filter(), reduce() and list comprehensions.

Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list