It seems is-prime
and .is-prime
treat their arguments differently:
> is-prime('11')
True
> '11'.is-prime
No such method 'is-prime' for invocant of type 'Str'
in block <unit> at <unknown file> line 1
> is-prime(2.5)
False
> (2.5).is-prime
No such method 'is-prime' for invocant of type 'Rat'
in block <unit> at <unknown file> line 1
Here's the routine definition from the Int class
proto sub is-prime($) is pure {*}
multi sub is-prime(Int:D \i) {
nqp::p6bool(nqp::isprime_I(nqp::decont(i), nqp::unbox_i(100)));
}
multi sub is-prime(\i) {
i == i.floor
&& nqp::p6bool(nqp::isprime_I(nqp::decont(i.Int), nqp::unbox_i(100)));
}
In the second multi
the isprime_I
converts its argument with .Int
. Anything that has that method can then return an integer that might be prime.
This unbalance one of the things I don't like about Perl 6. If we have a routine that can do it this way we should move the method higher up in the class structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With