datetime.iterdate

Christopher T King squirrel at WPI.EDU
Mon Jul 12 18:11:30 CEST 2004


On Mon, 12 Jul 2004, Christos TZOTZIOY Georgiou wrote:

> On Mon, 12 Jul 2004 09:20:38 -0400, rumours say that Christopher T King
> <squirrel at WPI.EDU> might have written:
> 
> [snip of a<=x<=b proposition to replace xrange]
> 
> >To work perfectly, my 
> >proposal needs only a slight change in the parser (to compile a<b<c as 
> >(a<b)&(b<c) rather than a<b and b<c); I'm not sure how much this would 
> >affect existing code though.
> 
> A lot of code is based on "x and y" evaluating y only if x is true...

Oh no, I don't mean to replace "x and y" with "x&y", I mean to replace the
expansion of "x<y<z" (which is currently "x<y and y<z") with
"(x<y)&(y<z)". This /would/ slightly change the semantics of the x<y<z
construct, but I pity the developer that relies on the short-circuitting
of the evaluation of 'z' if y<x is False (even though it is guaranteed by
the docs); any code that would be broken would have to look something like
this:

if do_A()==True==do_something_requiring_A_to_have_returned_True():
   print 'Success!'

Nevertheless, perhaps a better expansion of x<y<z that would preserve 
the original semantics would be:

e=x<y
if e:
    e&=y<z
return e




More information about the Python-list mailing list