[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Operator precedence and unary minus
- From: dyngeccetor8 <dyngeccetor8@...>
- Date: Tue, 22 May 2018 22:32:53 +0300
On 05/22/2018 07:52 AM, Egor Skriptunoff wrote:
> On Tue, May 22, 2018 at 1:57 AM, dyngeccetor8 wrote:
>
>>
>> Lua 5.3 has four unary operators: "#", "~", "-", "not".
>> Lowering priority of "-" looks inconsistent.
>> Lowering priority of all unary operators hurts more than cures.
>>
>>
> Unary operators are very different.
> Why do you want all unary operators to have the same priority?
> I see no point in it.
>
I find it easy to state that all unary operators have the same
priority than to explain why unary minus is so different.
By the way, "~ - 1" is "0" now. After you change it'll become
"- ~ 1" which is "2".
Your well explained case with non-symmetric "mod" is one of
features of languages which have to be kept in mind.
Just like platinum question about "broken" "#" operator.
--
I believe all unary operators should have highest priority.
Current operator priorities:
3.4.8 – Precedence
Operator precedence in Lua follows the table below, from lower to higher priority:
or
and
< > <= >= ~= ==
|
~
&
<< >>
..
+ -
* / // %
unary operators (not # - ~)
^
-- https://www.lua.org/manual/5.3/manual.html
So "- 2 ^ 2" is "-4.0" and to square length of string "s" you
have to write "(# s) ^ 2".
-- Martin