[swift-evolution] Strings in Swift 4

Thorsten Seitz tseitz42 at icloud.com
Mon Jan 30 00:33:47 CST 2017


I prefer c[i...]

After all, why should it mean c[i...c.endIndex] and not c[i...c.lastIndex]? With the latter interpretation it is not just typographically nicer but also consistent.

-Thorsten 


Am 23.01.2017 um 00:40 schrieb Chris Lattner via swift-evolution <swift-evolution at swift.org>:

>> In my experiments with introducing one-sided operators in Swift 3, I was not able to find a case where you actually wanted to write `c[i...]`. Everything I tried needed to use `c[i..<]` instead. My conclusion was that there was no possible use for postfix `...`; after all, `c[i...]` means `c[i...c.endIndex]`, which means `c[i..<c.index(after: c.endIndex)]`, which violates a precondition on `index(after:)`.
> 
> Right, the only sensible semantics for a one sided range with an open end point is that it goes to the end of the collection.  I see a few different potential colors to paint this bikeshed with, all of which would have the semantics ā€œc[i..<c.endIndex]ā€:
> 
> 1) Provide "c[i...]":
> 2) Provide "c[i..<]":
> 3) Provide both "c[i..<]ā€ and "c[iā€¦]":


More information about the swift-evolution mailing list