Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-26 Thread Neil Schemenauer
On Fri, Aug 26, 2005 at 06:21:58PM +0200, Alain Poirier wrote: > For example, I often use this class to help me in functional programming : > > _marker = () [...] You should not use an immutable object here (e.g. the empty tuple is shared). My preferred idiom is: _marker = object() Cheer

Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-26 Thread Alain Poirier
Le Vendredi 26 Août 2005 16:57, Guido van Rossum a écrit : > On 8/25/05, Ian Bicking <[EMAIL PROTECTED]> wrote: > > More generally, I've been doing some language comparisons, and I don't > > like literal but non-idiomatic translations of programming patterns. > > True. (But that doesn't mean I thin

Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-26 Thread Guido van Rossum
On 8/25/05, Ian Bicking <[EMAIL PROTECTED]> wrote: > More generally, I've been doing some language comparisons, and I don't > like literal but non-idiomatic translations of programming patterns. True. (But that doesn't mean I think using generators for this example is great either.) > So I'm con

Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-25 Thread Ian Bicking
Andrew Koenig wrote: >>A closure based accumulator (using Scheme): >> >>(define (accum n) >> (lambda (incr) >> (set! n (+ n incr)) >> n)) >>(define s (accum 0)) >>(s 1) ; -> 1 == 0+1 >>(s 5) ; -> 6 == 1+5 >> >>So I thought the generator version might look like: >> >>def accum(n): >> while

Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-25 Thread Andrew Koenig
> A closure based accumulator (using Scheme): > > (define (accum n) > (lambda (incr) >(set! n (+ n incr)) >n)) > (define s (accum 0)) > (s 1) ; -> 1 == 0+1 > (s 5) ; -> 6 == 1+5 > > So I thought the generator version might look like: > > def accum(n): > while 1: > incr =

Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-25 Thread Ian Bicking
Phillip J. Eby wrote: > At 02:10 PM 8/25/2005 -0500, Ian Bicking wrote: > >>I was trying to translate a pattern that uses closures in a language >>like Scheme (where closed values can be written to) to generators using >>PEP 342, but I'm not clear exactly how it works; the examples in the PEP >>ha

Re: [Python-Dev] PEP 342: simple example, closure alternative

2005-08-25 Thread Phillip J. Eby
At 02:10 PM 8/25/2005 -0500, Ian Bicking wrote: >I was trying to translate a pattern that uses closures in a language >like Scheme (where closed values can be written to) to generators using >PEP 342, but I'm not clear exactly how it works; the examples in the PEP >have different motivations. Sinc