On Tue, 28 Jan 2020, Simon Proctor wrote: > So some recent conversations covered the Range method on numeric types like > Int > > So Int.Range gives the range of valid values -Inf^..^Inf which is neat. > > Then I thought I'd try UInt.Range and got 0..^Inf > > Ah Ha! Thinks I. I have a plan. What if I try this? > > my subset OneToTen of Int where { not .defined or 1 <= $_ <= 10 }; > say OneToTen.Range; > > And it gives ... > > -Inf^..^Inf > > And now I'm a bit confused. The Docs say the UInt is just a subset > https://docs.raku.org/type/UInt > > So how does it have it's own Range? >
It's simply special-cased in the Int.Range implementation: https://github.com/rakudo/rakudo/blob/d8e859d000fa658766266a45f99e58661dec7b0e/src/core.c/Int.pm6#L239 As a consequence of the implementation checking the .^name, you can make Rakudo appear very confused: subset UInt of Int where 1000 .. 1002; say UInt.Range; #= 0..^Inf Arguably, the subset declarator could probably make the case where the matcher is an explicit Range as above DWIM, but as soon as arbitrary code is involved, as in your OneToTen, there is no hope to make a sensible Range method. Regards, Tobias -- "There's an old saying: Don't change anything... ever!" -- Mr. Monk