lua-users home
lua-l archive

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


On Thu, Jul 21, 2016 at 1:25 AM, Martin <eden_martin_fuhrspam@gmx.de> wrote:
On 16-07-20 04:12 AM, Egor Skriptunoff wrote:
> The key idea of my suggestion is to make distinction between numeric
> operations.
>
> So, for example, addition "+" should be replaced by two different
> operations:
> 1) normal addition (true mathematical addition on real numbers);
> 2) cyclic addition (addition modulo 2^64).
>
> These operations should have different operation symbols,
> for example, "+" for normal and "[+]" for cyclic.

As I understand you offer to make separate syntax representations for
at least four binary operators: + - * / . And possibly for ^ % | ~ &
<< >> < > == <= >=

Yes, according to my suggestion, five new operations
(and 5 new metamethods) should be introduced:
[+] [-] [*] [/] [%]

Some operations are already always-cyclic,
so no need for introducing of their counterparts:
| ~ & << >>

Some operations have the same semantics for both integers and floats,
so no need for introducing of their counterparts:
^ < > == <= >= ~=
(I doubt that anyone wants cyclic exponentiation, where 2[^]100 == 0)

 
But the final result is the same: operands converted to one type and
then operation is performed. By Michael Nelson's proposal you should
covert type explicitly: "print(math.pi * d^2 / to_float(1 << 2))".
By your proposal, conversion is implicit, determined by operator:
"mid = (left [+] right) [/] 2".

I'd prefer avoid adding new operators. Indeed, no operators may
be used at all: "div(mul(math.pi, sqr(d)), to_number(4))"

Explicit function calls (for converting or for math operations) are too boring to use.
That's why Lua has migrated from function-like-notation to operation-like-notation
for bitwise stuff ("bit32.band" -> "&" and so on) at the cost of introducing new syntax,
and I like it.
Mathematical expressions are better to look like math formulas whenever possible.