[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ternary operator patch
- From: David Kastrup <dak@...>
- Date: Wed, 15 Sep 2010 09:49:02 +0200
Ryota Hirose <hirose.ryota@gmail.com> writes:
> Hello Lua Hackers,
>
> 2010年9月14日 20:23:20 UTC+9 David Kastrup <dak@gnu.org>:
>
> Lua is an imperative language: this tries to fudge
> existing control functionality into expressions, inventing a
> completely
> separate syntax not recognizably related.
>
>
> and/or operators has control functionality, doesn't it? and/or are
> logical operators, so it is not necessary to define the order of
> evaluation arguments ,like arithmetic operators, but Lua does.
Ada has "and then" and "or else" operators to distinguish short circuit
evaluation from normal boolean expressions.
More obvious semantics. Of course, at the cost of overloading "then"
and "else".
Lua's (x and y or z) would become (x and then y or else z) which looks a
bit less idiomatic but still is likely to surprise people when y is
false or nil because for a human reader, "and then" and "or else" are
more or less considered alternatives at the same level.
The main problem with (x and y or z) is that it is an idiom, and it does
not do the right job for what the idiom stands for.
It is not likely that a syntactic compression of a real "if" is going to
gain the same expressive power. One could, in sort of a perverse twist,
write the desired idiom as
(x and y or else z)
That seems in the Lua spirit, is short enough to compete as an idiom,
and does not require additional keywords. It is not likely to be
self-evident for readers knowing the "or else" keyword from other
languages.
I'd search for a syntax along that lines if really necessary. Because
it appears obvious to me that the (x and y or z) idiom needs to get
phased out by something similarly handy with the semantics expected from
that idiom.
--
David Kastrup
- References:
- Re: Ternary operator patch, Henk Boom
- Re: Ternary operator patch, steve donovan
- Re: Ternary operator patch, Geoff Leyland
- Re: Ternary operator patch, steve donovan
- Re: Ternary operator patch, Miles Bader
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Miles Bader
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Jonathan Castello
- Re: Ternary operator patch, Roberto Ierusalimschy
- Re: Ternary operator patch, Enrico Tassi
- Re: Ternary operator patch, Doug Rogers
- Re: Ternary operator patch, Ryota Hirose
- Re: Ternary operator patch, Ryota Hirose
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Miles Bader
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Ryota Hirose