[Python-bugs-list] [ python-Bugs-223520 ] Example code doesn't work

noreply@sourceforge.net noreply@sourceforge.net
Wed, 17 Jul 2002 10:58:29 -0700


Bugs item #223520, was opened at 2000-11-26 21:10
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=223520&group_id=5470

Category: Documentation
Group: Not a Bug
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Example code doesn't work

Initial Comment:
In section 4.7.4 the code snippet:

def make_incrementor(n):
    return lambda x, incr=n: x+incr

doesn't seem to work.  It seems to be returning the lambda function handle instead.  This occurred on Win98, using python interactively.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2002-07-17 10:58

Message:
Logged In: NO 

Sorry, I didn't think about that.  I shall upgrade to 2.2.1
post-haste.  I'm not used to languages that evolve that
quickly, so I guess I assumed RH7.2 would have the latest
version.  Nope -- it has 1.5.2.  :)

Thanks,
Jeremy Weatherford

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-07-17 10:52

Message:
Logged In: YES 
user_id=31435

The need for the default argument trick went away when 
Python added lexical scoping.  Make sure the version of the 
docs you're looking at are correct for the version of Python 
you're running.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2002-07-17 10:39

Message:
Logged In: NO 

This is strange... the sample code in section 4.7.4 at
www.python.org/doc/current/tut/node6.html shows:

def make_incrementor(n):
     return lambda x: x + n

which doesn't work.  Did the change to add a default
parameter get undone somehow?

Thanks,
Jeremy Weatherford

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2000-11-27 07:50

Message:
The doc update is fine, Tim.

If you want me to review something, don't close the bug!

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2000-11-26 22:46

Message:
Not a bug.  It's *supposed* to return a (anonymous) function.  I added a little more to the tutorial's example (rev 1.121):

>>> def make_incrementor(n):
...     return lambda x, incr=n: x+incr
...
>>> f = make_incrementor(42)
>>> f(0)
42
>>> f(1)
43
>>>

Assigned to Fred for doc review, but already closed the bug report.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=223520&group_id=5470