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

Hans Huck gutgedacht at gmx.de
Thu Apr 14 19:57:57 CDT 2016

Erica Sadun via swift-evolution <swift-evolution at ...> writes:
> > On Apr 14, 2016, at 1:42 PM, Hans Huck via swift-evolution
<swift-evolution <at> swift.org> wrote:
> > Please elaborate. How could
> > 
> > for i in (1...10).by(3)
> > 
> > possibly be misinterpreted?
> > 
> (1..<11), (4..<14), (7..<17)...

Or (3..<30)? :)

With that reasoning, "for in" would have to be changed to "for each" to
avoid possible misinterpretation; after all, "i" could be a range and "for i
in" could test if it's a subrange of (1...10).

Basically, there is no such thing as "unmistakable", not least because the
very same keywords and symbols are being used for different purposes in
different languages. There are only degrees of clarity.

Anyway, why not just make it .step() then, like in Ruby?

Instead of a "by" keyword, I'd be happy with syntactic sugar in the form of

for i in p1..<p2 step x

too, btw.

-- Hans

More information about the swift-evolution mailing list