lua-users home
lua-l archive

Re: Ternary operator patch

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ryota Hirose <hirose.ryota@gmail.com> writes:
> Hello, Lua Hackers,
>
> 2010年9月15日 David Kastrup <dak@gnu.org>
>
> (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
((A and B) and C or else D)
> y = A or B and C or else D
A or (B and C or else D)
> z = A and B or C and D or else E
(A and B) or (C and D or else E)
The real ugliness is something else:
A and B and C or else D or else E
would appear to have to be read as
(A and (B and C or else D) or else E)
and that introduces some not strict left-to-right ordering into the
construct that is not appealing.
> 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.
Why?
>  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.
Lua has quite fewer operator priorities than C (and Pascal has even
fewer), and I should like to see evidence that more people get confused
by the operator priorities of Pascal than those of C.
-- 
David Kastrup

AltStyle によって変換されたページ (->オリジナル) /