TSa wrote:
HaloO,
David Green wrote:
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?
I see no problem when a Range matches for values which are not produced
by a RangeIterator. I expect 2.5 ~~ 1..5 to be true even though 2.5 is
not in 1,2,3,4,5.
I suspect that the double meaning of Ranges is going to confuse some
people and bite others. If things stay as they are, I hope that the use
of :by will be flagged as a syntax error if used in literal Range smart
matching. Of course, that doesn't help the unsuspecting when variables
are being used, ala 2.5 ~~ $myrange.
(For the record, 2.5 ~~ '!'..5 is also true on my system, although I
don't know why! I certainly wouldn't expect it though :)
The same applies for 'aaa' ~~ 'aa'..'az'. I find this
quite natural.
Not sure if you're saying that's something you'd like or if you think
that that's something already there. It doesn't match for me using
recent(ish) Rakudo. Of course, that could just be me! :)
I'd personally prefer it if Ranges just did lists, including when smart
matching, but had an interval method or such like for explicit matching
against the endpoints, e.g.
2.5 ~~ interval(1..5) # or
2.5 ~~ $myrange.interval
I'm new in town though, so I'll happily admit that I don't know the full
implications of such a change. Having context-insensitive Ranges DWIM's
better to me, but DWIMery, like beauty, is clearly in the eye of the
beholder! :)
Cheers,
--
smuj