# Re: generality of Range

Moritz Lenz wrote:
Darren Duncan wrote:
However, I still don't see how one would retrieve the distinction between say "1..10" and "1^..^10". I suggest that an extra 2 methods such as .min_is_outside and .max_is_outside (each returns a Bool) could fit the bill, and in fact since I have Pugs write access I think I'll go make that addition myself in the above S03 section.

Great.
Rakudo currently uses from_exclusive and to_exclusive, but since ranges
now always have \$.from < \$.to, I see no reason to stick with "from" in
favor of "min", and "to" in favor of "max".

As seen in r28612, I went and made my change, but I decided to use shorter and probably better-descriptive names .min_excl and .max_excl, since both in math parlance as well as the existing S03 docs I was adding to, the base terms "include" and "exclude" were already in use.

Now I was going to ask how to represent endpoints that are "whatever" if "whatever" is orthogonal to type, but then I realized the answer is simply to use a Whatever object, which is one of the 4 "Undefined types" mentioned in S02.

For example, if someone said:

my \$r = \$foo..*;
my \$min = \$r.min;  # \$foo's value
my \$max = \$r.max;  # Whatever.new()

Now maybe it would be reasonable for .max to return +Inf if \$foo was an Int, but I would expect that for any type where \$foo doesn't have a concept of positive-infinity, a * would just be Whatever.new() by default.

I'd just say that Range.min and Range.max return exactly what you put
into it - (1..*).max should return * (which is a Whatever object),
(1..Inf).max should return Inf.

That sounds like exactly what I would prefer to happen.

Now, another tangent that I was going to raise ideas order-comparison-sensitive operations in general.

While it makes perfect sense for some type definitions to have "cmp" et al built-in, meaning that all order-comparison-sensitive operations such as "cmp" and "sort" and "before" and "minmax" and Range/interval value membership just work for them without extra help, I believe that it should be possible to apply a "cmp" at the place where any order-comparison-sensitive operations are *used*, not just in the type definitions of their operands.

map { \$^a mycmp \$^b } @values  # spelling ?

But I believe one should be able to do that with "minmax" or Range uses or "before" or what-have you in a generic sense as well; for example:

\$a ∈ \$b..\$c ordered using { \$^a mycmp \$^b }  # ordered ... applies to ∈
minmax @values ordered using { \$^a mycmp \$^b }

Now mind you, its possible that support for what I'm saying already exists with another syntax, perhaps using :trait syntax, but I don't recall.

But this is important, especially since often a type may have multiple innate conceptions of order, and you are best to pick one at time of use; for example, what collation to use for sorting text, you may not want to encode into the Str objects but just declare at the time of sorting/etc.

And it is important because it what lets you potentially order values of any types at all.

-- Darren Duncan