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

Thorsten Seitz tseitz42 at icloud.com
Mon May 9 13:02:04 CDT 2016


> Am 03.05.2016 um 13:42 schrieb Hans Huck via swift-evolution <swift-evolution at swift.org>:
> 
> 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.“

I meant „more general“ in the sense of allowing reuse (of these methods) in other contexts and of allowing more powerful abstractions (in this case expressed by simple methods on sequences) to be used easily.
For the same reason I would not rate Swift’s for-loop as more general than Scala’s for-loop which is more akin to Haskell’s monadic do-notation. More basic or more low level, yes, but not more general.

-Thorsten


> 
> 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 ? :)
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list