[swift-evolution] A (better) Swift Equivalent For The Classical For-Loop With Numeric Scalars

Erica Sadun erica at ericasadun.com
Sun Mar 20 13:13:33 CDT 2016

> On Mar 19, 2016, at 4:10 PM, Gavin Eadie via swift-evolution <swift-evolution at swift.org> wrote:
> Finally, I'll note that when SE-0007 was being considered, I asked how I might do the second case
> (I needed to span Doubles from X to Y in jumps of Z.  The best answer (of several), at that time, was:
>     extension ClosedInterval where Bound: Strideable {
>         func by(n: Bound.Stride) -> StrideThrough<Bound> {
>             return start.stride(through: end, by: n)
>         }
>     }
> and 

Right now, I believe floating point strides are broken. I started working on a proposal to address this by 
moving them into their own stride implementations instead of genericizing them with integers.
(https://github.com/apple/swift-evolution/blob/master/proposals/0050-floating-point-stride.md <https://github.com/apple/swift-evolution/blob/master/proposals/0050-floating-point-stride.md>)

After talking with Dave Abrahams, it looks like he's going to be able to address the issue as a
part of his indexing model work. I have withdrawn the proposal.

Spanning doubles from X to Y in jumps of Z is particularly problematic in traditional for loops
because of the errors accumulated at each iteration. There are more details about this issue 
in the proposal link.

Swift has many use-cases where we don't really mind if there are minor calculation errors 
because the real-world experience of the user doesn't change (did that timer fire 0.0001 seconds early?),
other use-cases that are inherently decimal in nature (currency, many graphing applications, where
0.1 and 0.25 matter), and still yet others where calculation errors matter but the numbers
aren't nicely decimal (trigonometry, among others). Swift should support these all.

-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160320/bcbf730e/attachment.html>

More information about the swift-evolution mailing list