lua-users home
lua-l archive

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


On Tue, Nov 13, 2012 at 10:27 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 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
>

+1 on two-return-value __divmod.

Not sure I like /% though; while it's descriptive, it doesn't match
integer division in other languages (and it doesn't look very visually
satisfying; it doesn't feel like it's a single token).

/s/ Adam