[Python-Dev] Re: Trinary Operators

Aahz aahz@pythoncraft.com
Thu, 6 Feb 2003 15:36:32 -0500


On Thu, Feb 06, 2003, Guido van Rossum wrote:
>Gerald S. Williams:
>>
>> I'm an even-day fan of trinary operators myself, but this opens too
>> many questions. For example, with regard to short-circuiting, it will
>> be inconsistent with other expressions at some level in either form
>> or function.
>
> How so?  If we give 'or' (and hence 'and') a higher priority --
> i.e. binding tighter -- than 'if' and 'else', it's unambiguous to the
> parser and also consistent with the if statement:
> 
>   if x and y:
>      print 1
>   else
>      print 0
> 
> means the same as
> 
>   print 1 if x and y else 0
> 
> This is also similar to how lambda groups relative to and/or (and/or
> has a higher priority).

Are they really equivalent?  What about

    print h() if f() and g()

versus

    if f() and g():
        print h()

Does g() get called if f() is false?  What about h()?
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Argue for your limitations, and sure enough they're yours."  --Richard Bach