Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(no) fast boolean evaluation ?
- From: evan at yelp.com (Evan Klitzke)
- Subject: (no) fast boolean evaluation ?
- Date: Thu, 2 Aug 2007 16:19:24 -0700
On 8/2/07, Stef Mientki <S.Mientki-nospam at mailbox.kun.nl> wrote:
> hello,
>
> I discovered that boolean evaluation in Python is done "fast"
> (as soon as the condition is ok, the rest of the expression is ignored).
>
> Is this standard behavior or is there a compiler switch to turn it on/off ?
>
This is standard behavior in every language I've ever encountered. If
you are evaluating an and/or with side effects and you need both side
effects to occur, you can trivially write functions implementing this
behavior, e.g.
def a():
print 'foo'
def b():
print 'bar'
def my_and(lh, rh):
return a and b
Then my_and(a(), b()) will evaluate both a and b and print both foo
and bar even though a() is False.
--
Evan Klitzke <evan at yelp.com>
- Follow-Ups:
- (no) fast boolean evaluation ?
- From: Joshua J. Kugler
- (no) fast boolean evaluation ?
- References:
- (no) fast boolean evaluation ?
- From: Stef Mientki
- (no) fast boolean evaluation ?
- Prev by Date: __call__ considered harmful or indispensable?
- Next by Date: (no) fast boolean evaluation ?
- Previous by thread: (no) fast boolean evaluation ?
- Next by thread: (no) fast boolean evaluation ?
- Index(es):