lua-users home
lua-l archive

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


2012/11/14 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:

>
> I have been playing a little with the idea of introducing an integer
> type in Lua. I have intended to present some initial thoughts in the
> workshop.
>
> The overall idea is quite simple. There will be two kinds of numbers,
> integers and floats. All operations except division result in an
> integer if both operands are integers and in float otherwise. There
> will be two divisions: float division (the usual '/') always have
> a float result, integer division ('//'??) always have an integer
> result.

A new operator requires a new metamethod. Suggestion:

__divmod(op1, op2)
   Returns two results: quotient and remainder.

Semantics exactly as for other functions with multiple return values.
Only the first return value is kept in expressions, list constructors
except for the last item, etc.

This definition screams for the symbol `/%`.

> q, r = 42 /% 10  --> 4,2

Dirk