PEP308: Yet another syntax proposal

Andrew Koenig ark at research.att.com
Tue Feb 11 10:02:54 EST 2003


Dennis>         <satanic-counsel> "And" and "Or" are technically
Dennis> isolated to the evaluation of a condition, and not to the
Dennis> processing of alternatives (if any) selected by the result of
Dennis> the condition. In normal languages which offer
Dennis> short-circuiting the result of the condition is strictly a
Dennis> Boolean; it is only because of the Python semantics which
Dennis> result in returning the actual object which was last evaluated
Dennis> rather than True/False which even made the work-around
Dennis> possible. Therefore there is no valid precedent for using
Dennis> late-binding/lazy-evaluation of the branches selected by a
Dennis> condition. </satanic-counsel>

...

Dennis>         Okay, can someone help me off this picket fence? <G>

Python is not the only language in which the result of an "and"
or "or" is one of its operands rather than a boolean.  Icon (the
work of Ralph Griswold and friends at the University of Arizona)
has similar behavior.  In fact, in Icon, every expression is a
generator that can yield a sequence of results.  The convention
in Icon is that an empty sequence indicates failure.

The following Icon operations are relevant to this discussion:

        x1 & x2         fails if x1 fails; otherwise yields x2

        x1 | x2         generator concatenation (which has the
                        effect of logical "or" if a null sequence
                        indicates false)

        if expr1 then expr2 else expr3
                        if expr1 is empty, the result is expr3;
                        otherwise the result is expr2

I'm not sure which way this example argues, but think it's worth
pointing out in any case.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list