[ZPT] | inefficiency/bug

Chris Withers chrisw@nipltd.com
Fri, 29 Mar 2002 08:25:05 +0000


Ron Bickers wrote:
> 
> I recently had a similar issue with the test() function.  Perhaps they're
> related?
> 
>   test(a, a[b], c)
> 
> Since all three are always evaluated, a[b] gives an error even if the test
> for 'a' is false.

Well, if you think about how python is evaluated, then there's no real way
around this without changing what I'd guess is a pretty basic part of the
language :-S
(unless someone could persuade Guido to make the test function a keyword, which
I very much doubt..)

...that said, I would happily see a ? a[b] : c, as you get in C...

Or maybe, slightly nicer wording:

if a then a[b] else c

..which doesn't currently work :-S

> The current solution is to exploit Python's short circuiting, as in:
> 
>   python:(a and a[b]) or c
> 
> > What's the best way to tackle this?
> 
> The best way, IMO, would be to "fix" | to mirror Python's behavior.

Yup, that's a given, I'd like to see the test problem solved properly too...

cheers,

Chris