Re: setting variables in outer functions

2007-11-04 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit : > "Chris Mellon" <[EMAIL PROTECTED]> writes: > > >>I have no idea why someone who already has a working, object system >>would want to implement their own on top of closures. > > > This subthread is getting ridiculous -- closures are *not* useful only > for implementing

Re: setting variables in outer functions

2007-11-01 Thread Neil Cerutti
On 2007-11-01, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Duncan Booth <[EMAIL PROTECTED]> writes: > >> In real life code methods are used to implement callbacks > > When I said "closures are used ...", I wasn't trying to be > preachy about how I think callbacks should be implemented, just > explai

Re: setting variables in outer functions

2007-11-01 Thread Dustan
On Oct 31, 5:59 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On Oct 31, 2007 5:49 PM, Dustan <[EMAIL PROTECTED]> wrote: [snip] I'm not going to respond to any of this, but I'm just going to say: I'm not claiming that the use of closures is common. I'm just claiming that it can be useful. I have

Re: setting variables in outer functions

2007-11-01 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes: > In real life code methods are used to implement callbacks When I said "closures are used ...", I wasn't trying to be preachy about how I think callbacks should be implemented, just explaining the use (and usefulness) of *closures*. I'm not saying closur

Re: setting variables in outer functions

2007-11-01 Thread Duncan Booth
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > In real-life code, closures are used to implement callbacks with > automatic access to their lexical environment without the need for the > bogus additional "void *" argument one so often sees in C callbacks, > and without communication through global var

Re: setting variables in outer functions

2007-10-31 Thread Diez B. Roggisch
Hrvoje Niksic schrieb: > "Chris Mellon" <[EMAIL PROTECTED]> writes: > >> I have no idea why someone who already has a working, object system >> would want to implement their own on top of closures. > > This subthread is getting ridiculous -- closures are *not* useful only > for implementing objec

Re: setting variables in outer functions

2007-10-31 Thread Hrvoje Niksic
"Chris Mellon" <[EMAIL PROTECTED]> writes: > I have no idea why someone who already has a working, object system > would want to implement their own on top of closures. This subthread is getting ridiculous -- closures are *not* useful only for implementing object systems! The object system thing

Re: setting variables in outer functions

2007-10-31 Thread Chris Mellon
On Oct 31, 2007 5:49 PM, Dustan <[EMAIL PROTECTED]> wrote: > On Oct 31, 7:08 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > > > Dustan <[EMAIL PROTECTED]> wrote: > > > On Oct 30, 11:29 am, Duncan Booth <[EMAIL PROTECTED]> > > > wrote: > > >> Neil Cerutti <[EMAIL PROTECTED]> wrote: > > >> > It's allo

Re: setting variables in outer functions

2007-10-31 Thread Dustan
On Oct 31, 7:08 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > Dustan <[EMAIL PROTECTED]> wrote: > > On Oct 30, 11:29 am, Duncan Booth <[EMAIL PROTECTED]> > > wrote: > >> Neil Cerutti <[EMAIL PROTECTED]> wrote: > >> > It's allows a standard programming idiom which provides a > >> > primitive form of

Re: setting variables in outer functions

2007-10-31 Thread Duncan Booth
Dustan <[EMAIL PROTECTED]> wrote: > On Oct 30, 11:29 am, Duncan Booth <[EMAIL PROTECTED]> > wrote: >> Neil Cerutti <[EMAIL PROTECTED]> wrote: >> > It's allows a standard programming idiom which provides a >> > primitive form of object oriented programming using closures to >> > represent state. >>

Re: setting variables in outer functions

2007-10-31 Thread Dustan
On Oct 30, 11:29 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > Neil Cerutti <[EMAIL PROTECTED]> wrote: > > It's allows a standard programming idiom which provides a > > primitive form of object oriented programming using closures to > > represent state. > > > def account(opening_balance): > > bal

Re: setting variables in outer functions

2007-10-30 Thread Bruno Desthuilliers
brad a écrit : > Tommy Nordgren wrote: > >>> def outer(avar=False): >>> print avar >>> if avar == True: >>> return >>> >>> def inner(avar=True): >>> print avar >>> return avar >>> >>> outer(inner()) >>> >>> outer() > > >> This is not a general s

Re: setting variables in outer functions

2007-10-30 Thread Duncan Booth
Neil Cerutti <[EMAIL PROTECTED]> wrote: > It's allows a standard programming idiom which provides a > primitive form of object oriented programming using closures to > represent state. > > def account(opening_balance): > balance = opening_balance > def get_balance(): > nonlocal balance >

Re: setting variables in outer functions

2007-10-30 Thread Steven Bethard
Neil Cerutti wrote: > On 2007-10-29, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Hrvoje Niksic wrote: >>> Tommy Nordgren <[EMAIL PROTECTED]> writes: >>> Given the following: def outer(arg) avar = '' def inner1(arg2) # How can I set 'avar' here ? >>> I d

Re: setting variables in outer functions

2007-10-30 Thread Neil Cerutti
On 2007-10-29, Steven Bethard <[EMAIL PROTECTED]> wrote: > Hrvoje Niksic wrote: >> Tommy Nordgren <[EMAIL PROTECTED]> writes: >> >>> Given the following: >>> def outer(arg) >>> avar = '' >>> def inner1(arg2) >>> # How can I set 'avar' here ? >> >> I don't think you can, until

Re: setting variables in outer functions

2007-10-29 Thread Steven Bethard
Hrvoje Niksic wrote: > Tommy Nordgren <[EMAIL PROTECTED]> writes: > >> Given the following: >> def outer(arg) >> avar = '' >> def inner1(arg2) >> # How can I set 'avar' here ? > > I don't think you can, until Python 3: > http://www.python.org/dev/peps/pep-3104/ But it definit

Re: setting variables in outer functions

2007-10-29 Thread brad
Tommy Nordgren wrote: >> def outer(avar=False): >> print avar >> if avar == True: >> return >> >> def inner(avar=True): >> print avar >> return avar >> >> outer(inner()) >> >> outer() > This is not a general solution to this problem. Run my exam

Re: setting variables in outer functions

2007-10-29 Thread Hrvoje Niksic
Tommy Nordgren <[EMAIL PROTECTED]> writes: > Given the following: > def outer(arg) > avar = '' > def inner1(arg2) > # How can I set 'avar' here ? I don't think you can, until Python 3: http://www.python.org/dev/peps/pep-3104/ Currently the (ugly) solution is to change variabl

Re: setting variables in outer functions

2007-10-29 Thread Terry Reedy
"Tommy Nordgren" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Given the following: | def outer(arg) | avar = '' | def inner1(arg2) | # How can I set 'avar' here ? You cannot at present. You can only mutate mutable outer vars: def outer(arg): avar = ['']

Re: setting variables in outer functions

2007-10-29 Thread Tommy Nordgren
On 29 okt 2007, at 21.59, brad wrote: > Tommy Nordgren wrote: >> Given the following: >> def outer(arg) >> avar = '' >> def inner1(arg2) >> # How can I set 'avar' here ? > > Try this... works for me... maybe not for you? > > def outer(avar=False): > print avar > if a

Re: setting variables in outer functions

2007-10-29 Thread brad
Tommy Nordgren wrote: > Given the following: > def outer(arg) > avar = '' > def inner1(arg2) > # How can I set 'avar' here ? Try this... works for me... maybe not for you? def outer(avar=False): print avar if avar == True: return def inner(avar=True):

setting variables in outer functions

2007-10-29 Thread Tommy Nordgren
Given the following: def outer(arg) avar = '' def inner1(arg2) # How can I set 'avar' here ? - This sig is dedicated to the advancement of Nuclear Power Tommy Nordgren [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python