> On 11 Dec 2017, at 04:42, Sean McAfee <eef...@gmail.com> wrote:
> 
> I think of %% as being Perl 6's is-divisible-by operator, so I was a little 
> surprised to discover this behavior:
> 
> > 1 %% 0
> Attempt to divide 1 by zero using infix:<%%>
>   in block <unit> at <unknown file> line 1
> 
> The docs say a %% b is True if a % b is 0, so the error is as-designed, at 
> least.  But mightn't it make more sense for %% to just return False when 
> given a second zero operand?  After all, the answer to "is n divisible by 
> zero" is false for any n--there's no need to try to go through with the 
> division to ascertain this.

Note that x %% 0 returns a Failure ( https://docs.perl6.org/type/Failure ), 
which will be evaluated to False in a Boolean context.  So it is already doing 
what you want.  Only if you use it in a non-Boolean context, will the Exception 
of the Failure be thrown.

   say "foo" if 1 %% 0   # no output

   say "foo" unless 1 %% 0   # “foo”

If you type in 1 %% 0 in the REPL, you are forcing evaluation of the Failure as 
a string because it will try to “say” it.

    say 1 %% 0  # Attempt to divide 1 by zero using infix:<%%>


Hope this helps.


Liz

Reply via email to