On 2009-Aug-24, at 4:17 pm, Daniel Ruoso wrote:
Em Seg, 2009-08-24 às 23:50 +0200, Michael Zedeler escreveu:
The most elegant solution would be if the data types themselves
indicated their capabilities.
One thing I think you missed entirely is the fact that the infix:<..>
operator is a multi sub, so it falls to regular dispatch semantics,

But Michael's point was not about what's *possible*, but rather what's *reasonable*. Given that Ranges can act in two ways that lead to inconsistency, it would be less confusing to separate the list-kind from the interval-kind.

For certain discrete ordered types, like Int, both ways work out the same, and since Ints are the most common and most obvious use for Ranges, it's easy to overlook the confusion. The case with strings is a good example: it really doesn't make sense that a value not produced by a range nevertheless lies between its endpoints. Why not have a separate Interval type?

A Range might get implicitly cast to an Interval by using its endpoints; that leaves us open to the same confusion, although the context would help.
        # Assuming infix:<between> (Any, Interval)
        say 5 between [1, 10];
        say 5 between 1 .. 10;
        
        say 'aaa' ~~ 'aa' .. 'ba';      # false
        say 'aaa' between <aa ba>;      # true
        say 'aaa' between 'aa'..'ba';   # hm...


Come to think of it, the word "range" suggests ordering (like the related word "rank"), so perhaps Range is the right name for the interval-type, and "Series" should be the type that produces a series of values that may or may not have an innate ordering. (For example, you could produce a Complex series with: 5+5i .. 10+10i :by(1+1i).)



-David

Reply via email to