Newsgroups: gnu.misc.discuss,comp.lang.tcl,comp.lang.scheme,comp.lang.python
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!news.duke.edu!convex!cs.utexas.edu!math.ohio-state.edu!jussieu.fr!univ-lille1.fr!zaphod.crihan.fr!warwick!uknet!festival!edcogsci!jeff
From: jeff@aiai.ed.ac.uk (Jeff Dalton)
Subject: Re: Tcl/Lisp/Python: A "User" point of view
Message-ID: <CwwpMG.Ix8@cogsci.ed.ac.uk>
Sender: usenet@cogsci.ed.ac.uk (C News Software)
Nntp-Posting-Host: bute.aiai.ed.ac.uk
Organization: AIAI, University of Edinburgh, Scotland
References: <1994Sep27.085636.23932@paramount.nikhefk> <.nikhef.nl>nl>@.nikhef.UUCP> <BOBO.94Sep27093605@avogadro.arc.nasa.gov>
Date: Thu, 29 Sep 1994 19:47:04 GMT
Lines: 33
Xref: glinda.oz.cs.cmu.edu gnu.misc.discuss:18567 comp.lang.tcl:19659 comp.lang.scheme:10126 comp.lang.python:1792

In article <BOBO.94Sep27093605@avogadro.arc.nasa.gov> bobo@ptolemy.arc.nasa.gov writes:
>I was recently surfing through the net and saw that among the new
>features of the language Python was support for functional
>programming. I clicked and saw the following:
>
>    Lambda Forms
>    ============
>
>    By popular demand, a few features commonly found in functional
>    programming languages and Lisp have been added to Python. With the
>    lambda keyword, small anonymous functions can be created. Here's a
>    function that returns the sum of its two arguments: 
>
>      lambda a, b: a+b. 
>
>    Lambda forms can be used wherever function objects are
>    required. They are syntactically restricted to a single
>    expression.  Semantically, they are just syntactic sugar for a
>    normal function definition. Like nested function definitions,
>    lambda forms cannot reference variables from the containing scope,
>    but this can be overcome through the judicious use of default
>    argument values, e.g.
>
>
>	    def make_incrementor(n):
>		    return lambda(x, incr=n): x+incr

Can someone who knows Python explain what this does / how it works?

My guess is that the value of n is textually substituted for "n" in
"return lambda(x, incr=n): x+incr".  But I know nothing of Python.

-- jeff
