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

Howard Lovatt howard.lovatt at gmail.com
Tue Apr 5 15:40:41 CDT 2016


Yes I know what you are saying and I am suggesting changing that so that:

 (0 ... -9) and  (0 ..< -10)

Are both empty ranges rather than errors because they implicitly have a
'by' of 1.

On Wednesday, 6 April 2016, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:

> Howard, the point I am raising is that `0...(-9)` is not valid Swift
> because the first, "lower" bound is enforced to be less than the second,
> "upper" bound.
>
> The problem is that with that restriction certain types of half-open
> intervals, namely those where the lower bound is the one being excluded,
> cannot be represented as a Range either currently or in Dave A's branch.
> On Tue, Apr 5, 2016 at 3:30 PM Howard Lovatt <howard.lovatt at gmail.com
> <javascript:_e(%7B%7D,'cvml','howard.lovatt at gmail.com');>> wrote:
>
>> I much prefer (0 ... -9).by(-1) and  (0 ..< -10).by(-1)
>>
>> On Wednesday, 6 April 2016, Dave Abrahams via swift-evolution <
>> swift-evolution at swift.org
>> <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>> wrote:
>>
>>>
>>> on Tue Apr 05 2016, Xiaodi Wu <xiaodi.wu-AT-gmail.com> wrote:
>>>
>>> > On Mon, Apr 4, 2016 at 1:22 PM, Dave Abrahams <dabrahams at apple.com>
>>> wrote:
>>> >>
>>> >> on Sat Apr 02 2016, Xiaodi Wu <xiaodi.wu-AT-gmail.com> wrote:
>>> >>
>>> >>> [snip]
>>> >>>
>>> >>> Not included:
>>> >>> 1. I know Ranges are in flux, so I've held off on extending Range
>>> with
>>> >>> a striding(by:) method in this proof-of-concept.
>>> >>
>>> >> They're not in flux, except for not having been reviewed yet; they are
>>> >> settled in the swift-3-indexing-model branch.
>>> >
>>> > Did not know that. Will have to study what's there in more detail.
>>> >
>>> >>> 2. No attempt at the suggested stride(from:to:steps:) quite yet.
>>> >>
>>> >> #1 and #2 are mutually exclusive; we prefer #1 as it removes questions
>>> >> about the meaning of "to" or "through."
>>> >
>>> > I wasn't aware that was the thinking. Limiting strides to
>>> > `striding(by:)` removes the ability to express `stride(from: 0, to:
>>> > -10, by: -1)`
>>>
>>> IMO this:
>>>
>>>   (-9...0).reverse()
>>>
>>> is better than
>>>
>>>   stride(from: 0, to: -10, by: -1)
>>>
>>> What do you think?
>>>
>>> --
>>> Dave
>>>
>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>
>>
>>
>> --
>> -- Howard.
>>
>

-- 
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160406/83db8396/attachment.html>


More information about the swift-evolution mailing list