[swift-evolution] Strings in Swift 4
dabrahams at apple.com
Thu Feb 2 09:45:49 CST 2017
Sent from my iPad
> On Feb 2, 2017, at 7:11 AM, Matthew Johnson <matthew at anandabits.com> wrote:
>>> Furthermore, we emphatically do *not* need to make the distinction you claim between “infinite” and “incomplete” ranges, which *is* needless hairsplitting.
>> Strongly disagree, unless you can describe the semantics of the type WITHOUT giving it different semantics depending on how it is used.
> This is the point that convinced me. I’m going to take a closer look at Brent’s `RangeExpression` design which I must admit I only skimmed in the earlier discussion.
We already have exactly this situation with CountableRange (which will merge with Range when conditional conformances land). When used as a Collection, it means "every index value starting with the lowerBound and ending just before the upperBound". When used for slicing, it means, roughly, "take every one of the collection's indices that are in bounds." These are not the same thing. A collection's indices need not include every expressible value of the Index type between startIndex and endIndex.
The whole point of the name RangeExpression is to acknowledge this truth: ranges in Swift bits of syntax whose meaning is given partly by how they are used. In fact, now that I say it, in that respect ranges are not all that different any other type: the meaning of a Double or an Array<String> or a Bool is also interpreted by the methods to which it is passed, and can have completely different results depending on that context.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution