[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Operator precedence and unary minus
- From: Tim Hill <drtimhill@...>
- Date: Mon, 21 May 2018 15:44:24 -0700
> On May 21, 2018, at 3:32 PM, Albert Chan <albertmcchan@yahoo.com> wrote:
>
>
>> - a%m - b%n ~= - b%n - a%m
>> It's looks very weird
>
> Remove space between unary minus and variable,
> and some parenthesis, it does not look weird
>
> (-a % m) - (b % n) ~= (-b % n) - (a % n)
>
> You can do the same trick to make any expression weird:
>
> a * b+c * d+e / a ^ 3*c
>
>> I think it would be good to lower the priority of unary minus in Lua.
>> For example, unary minus may have the same priority as binary minus.
>>
>> -- Egor
>
> Even if the idea is sound, it is too late to fix precedence
>
> Anyway, how can it parse simple x / -y ?
>
>
You also need to be careful with literals and metatables. Consider:
-a * b
-10 * b
The same result? But what if b has a __mul metamethod?
—Tim