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

Hans Huck gutgedacht at gmx.de
Tue May 3 06:42:25 CDT 2016


Thorsten Seitz via swift-evolution <swift-evolution at ...> writes:
> 
> -1
> 
> I don't see the need for special syntax where a method can be easily used
and is more general.
> 
> -Thorsten 
>

That, dear Thorsten, is a non-argument. Why? Let's see, how about "I don't
see the need for a For-loop where a While-loop can be easily used and is
more general."

The "special syntax" summarized below by Vladimir is absolutely justified,
because

a) Zipf's Law and
b) forcing people to use convoluted OOP notation for basic, iterative tasks
is simply offensive.

-- Hans

 
> > Am 18.04.2016 um 17:28 schrieb Vladimir.S via swift-evolution
<swift-evolution <at> swift.org>:
> > 
> > On 15.04.2016 3:57, Hans Huck via swift-evolution wrote:
> > > 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
> > 
> > As for 'step' word: It seems like for now IMO this is the best
suggestion : very explicit, anyone knows what
> "step" means especially in context of loop, clear that "step" belongs to
for-in construction(not to
> range itself).
> > 
> > for i in 0..<10 step 2 {
> > }
> > 
> > for i in 0..<10 step -2 {
> > }
> > 
> > for i in 0.1..<10.5 step 0.5 {
> > }
> > 
> > all are mapped to needed ranges/intervals under the hood
> > Do you want some custom Range-specific methods to provide steps for loop
- no problems, use what you need.
> But don't force any of us to use (0..<10).striding(by:2) for myriads of
simple loops in our code.
> > 
> > I want to see such constructions in our Swift. Who is with me ? :)




More information about the swift-evolution mailing list