Putting aside the edge case of what to do when the divisor is zero, which could
also be tested for prior to attempting to call the operator:
An "is evenly divisible by" operator is an immensely useful one to have built-in
to the language; not only is "x %% y" much more direct to the real question than
"(x % y) == 0)", it can also be optimized because we don't actually care what
the quotient or remainder values are.
This being similar to how asking "is this list empty" is more direct and
optimizable than asking for the count of elements and comparing that to zero,
and it also has meaning for list-like uncountable collections.
-- Darren Duncan
On 2017-12-11 1:02 PM, Vittore Scolari wrote:
I think that this stems from a confusion between the divisibility problem in
integer number (on a ring) and the divisibility problem resolved by the perl6 %%
operator.
Personally I think that %% is useless while the former is useful and missing.
But I have nothing against useless operators
On Mon, Dec 11, 2017 at 9:56 PM, Darren Duncan wrote:
On 2017-12-11 12:22 PM, Sean McAfee wrote:
Well, not really. I don't think x %% 0 should return a Failure at all.
1 / 0 is an expression which can evaluate to no sensible value, so it
makes
sense to fail there. By the question "Is one divisible by zero?" has
the simple
answer "No."
I strongly disagree with you.
First of all, the reason there is no sensible value is that the answer is
BOTH "yes" and "no" at the same time, so you can't choose one. Zero DOES
divide evenly into anything, and typically does so an infinite number of
times. Bottom line, there is no good reason to answer either "yes" or "no"
for zero.
There are three distinct kinds of answers to the question "is x evenly
divisible by y":
1. When dividing x by y there are no leftovers (yes).
2. When dividing x by y there are leftovers (no).
3. When dividing anything by zero there is no sensible value (Failure).
It is very important to distinguish the above 3 cases.
The main use case of %% is to gate logic where if 2 numbers do evenly divide
we do some particular arithmetic with the results and if they don't but it
is a valid division then we do other particular arithmetic with the results.
The expression "x %% y" is to be equivalent to "(x % y) == 0)".
-- Darren Duncan