On 2009-Aug-27, at 3:11 pm, Mark J. Reed wrote:
Given how easy chained relational ops make explicit range checking with endpoints, e.g.
$a <= $x <= $b
I'd be perfectly happy with a Range smartmatching only the elements that you get out of the RangeIterator.

Yes -- although sometimes that would require separating out the $a and the $b parts, which is why having something to mean "between" would be handy.


On 2009-Aug-27, at 11:08 am, TSa wrote:
Note that order is not a prerequisite for a notion of range and range iteration. I think of ranges more like set and set iteration.

Except the meaning of the word "range" and the spec both indicate order: "(S03) A star on both sides prevents any type from being inferred other than the C<Ordered> role". Instead, can't the existing series operator take on the series aspects of ".."?

"..." can take a function on the RHS that generates new values, or it can take * to generate an arithmetic or geometric sequence. If only a single value is given as the LHS, it could use .succ, so 1...* or "a"...* would work like C<..> does.

I think the reason C<...> doesn't take a value other than * as the RHS is because of the problem of how to figure out whether the series will ever reach that value or not. But that's easy to figure out in the case of an arithmetic or geometric sequence, so 1, 3, 5 ... 99 should be OK, and 1, 3, 5 ... 100 should probably be an error. Maybe * || 100 as an endpoint could mean "go on forever or until hitting this value".

Similarly, it's simple to figure out whether .succ applied to strings will reach the endpoint or not. For an arbitrary function, it's not so easy. However, each type could have a "you can't get there from here" function for figuring out whether an endpoint is part of a series or not; if the endpoint passes that test, then you can use it; if it doesn't, or if there is no such function that can tell you, the only valid endpoint is *.

The :by adverb as applied to C<...> could take a value, which would be added (or handled according to the appropriate type when not dealing with Nums) just like it was with ".."; or :by could take a block, which would run that function. So 1 ... {foo} would be short for 1 ... *||Nil :by({foo}).

This way all the series stuff is gathered together, and a Range can simply represent a pair of starting and ending points without trying to be a list iterator as well. I expect its main use would be meaning "between": $foo ~~ $range. If a Range is not a Series, then there's no confusion as to whether being in the range means being in the series or not.


S03:
Alternately, we could treat an ellipsis as special when it follows a comma to better support traditional math notation.

That seems like an easy mistake to make, so treating it specially would be a good quirk.



-David

Reply via email to