[swift-evolution] Strings in Swift 4

Dave Abrahams dabrahams at apple.com
Mon Jan 30 13:35:31 CST 2017


on Sun Jan 22 2017, James Froggatt <swift-evolution at swift.org> wrote:

> Could we add subscript labels to the list of options? While keeping
> the range syntax is appealing, I'm concerned it may cause confusion if
> the operators are used out of context.
>
> The wording is up for debate, but something like this should be a fair alternative:
> items[from: i]
> items[upTo: i]
>
> Sorry if this has been covered elsewhere (can't find the answer in
> this thread), but my first questions on discovering these operators
> (my source of confusion) would be what happens if I try the following:
> let partialRange = 0..< //is this an infinite range?

If we implemented that syntax, it would be.  The proposal is that
half-open ranges without an upper bound would be illegal, but

  let partialRange = 0...

is just such an infinite range, which is useful in its own right.  For
example, let's deprecate enumerated():

   for (i, e) in zip(0..., elements) {
     print("\(i): \(e)")
   }

> let x = items[partialRange] //shouldn't this cause an out of bounds error?

Why should that be out-of-bounds?  Whether it is out-of-bounds would
depend on what items is.  If it's an array, that should be equivalent to

   let x = items[items.startIndex..<items.endIndex]

-- 
-Dave



More information about the swift-evolution mailing list