• Subject: Re: Ternary operator patch
• From: Ryota Hirose <hirose.ryota@...>
• Date: Thu, 16 Sep 2010 08:18:29 +0900

Hello, Lua Hackers,

2010/9/15 David Kastrup
(x and y or else z)

I think this notation is very ambiguous for the programmer, and not be friendly for parser.  If we introduced this notation, the keyword 'and' has two meanings, logical operator, and a half of ternary operator.  How do you feel about the following lines?

x = A and B and C or else D
y = A or B and C or else D
z = A and B or C and D or else E

In the view point of the parser, the logical operator 'and' has higher priority than 'or', but, for programmers, a ternary operator must have lower priority than logical operator.  So, when parser meets 'and', it cannot decide the priority of  the operator.  It must reserve the process, and search 'or else' forward.  If we assign same priority of logical 'and' and the ternary operator, it must confuse many programmers.

I understand through this discussion, that a ternary operator is different from a logical operator in the point of its process and a priority in a _expression_.  So, if we introduce a ternary operator, it's notation must be different than a logical or other operators.  and/or idiom is a good technique, but it may be harmful, like logical operation in MS-BASIC.  MS-BASIC had no logical operator, we used +,* as 'or','and'.  (I forgot how to describe 'not' with arithmetic operators...) The code became a sequence of magic words.

Thank you,
Ryota Hirose