Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12530

Re: Closures and Partial Function Application

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Closures and Partial Function Application
Date 2011-08-31 18:21 -0400
References <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.634.1314829322.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 8/31/2011 12:45 PM, Travis Parks wrote:
> I was a little disappointed the other day when I realized that
> closures were read-only.

'Were', in 2.x. The standard 2.x workaround for a single nonlocal is to 
wrap it in a list.

def f():
     i = [0]
     def g(): i[0] += 1
     for j in range(5): g()
     print(i)

f()
# 5

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Closures and Partial Function Application Travis Parks <jehugaleahsa@gmail.com> - 2011-08-31 09:45 -0700
  Re: Closures and Partial Function Application Arnaud Delobelle <arnodel@gmail.com> - 2011-08-31 17:55 +0100
  Re: Closures and Partial Function Application Chris Rebert <clp2@rebertia.com> - 2011-08-31 10:18 -0700
    Re: Closures and Partial Function Application Travis Parks <jehugaleahsa@gmail.com> - 2011-08-31 10:51 -0700
      Re: Closures and Partial Function Application Travis Parks <jehugaleahsa@gmail.com> - 2011-08-31 11:02 -0700
        Re: Closures and Partial Function Application Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-31 12:18 -0600
          Re: Closures and Partial Function Application Travis Parks <jehugaleahsa@gmail.com> - 2011-08-31 11:26 -0700
  Re: Closures and Partial Function Application "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-08-31 11:03 -0700
    Re: Closures and Partial Function Application Travis Parks <jehugaleahsa@gmail.com> - 2011-08-31 12:33 -0700
  Re: Closures and Partial Function Application Terry Reedy <tjreedy@udel.edu> - 2011-08-31 18:21 -0400
  Re: Closures and Partial Function Application Piet van Oostrum <piet@vanoostrum.org> - 2011-09-05 16:23 +0200

csiph-web