[swift-evolution] Feature proposal: Range operator with step

Dave Abrahams dabrahams at apple.com
Wed Apr 6 16:00:52 CDT 2016


on Wed Apr 06 2016, Erica Sadun <swift-evolution at swift.org> wrote:

>> On Apr 6, 2016, at 2:17 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>> Prohibiting StrideTo with floating-point ranges altogether would be
>> distressing. IMO, it's plenty distressing that backwards
>> floating-point StrideTo as it currently exists might go away.
>
> I wouldn't suggest doing so. I'm just saying that for a half-open interval, there is no max value
> so it makes no sense mathematically to have a first value and a
> negative step. 

I don't agree.  It seems to me that striding downwards over a half-open
range r should always begin with r.upperBound - s (modulo any necessary
adjustments to avoid FP error), where -s is the stride amount.  Why is
that mathematical nonsense?

Another point to consider: striding is also a sensible operation over
collections, and some ranges are collections.  The stride semantics must
coincide in those cases.  I expect that constraint narrows down the
reasonable semantic choices considerably.

> You're not so restricted with:
>
> * positive steps
> * closed intervals
>
> -- E
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
Dave



More information about the swift-evolution mailing list