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

Paul Ossenbruggen possen at gmail.com
Sat Mar 19 11:17:09 CDT 2016


I guess I am not in the forloopian camp. I spend far too much time, converting for i = 0; i < 4; i++) into something more modern like iterating over containers. If it is in the language, people will use it, not having it there makes people think about better ways of doing things rather than relying on muscle memory. I know it is a barrier for some but other languages such as Python don’t support this construct and no one will deny that Python is heavily used in numerics. 

- Paul

> On Mar 19, 2016, at 1:28 AM, ted van gaalen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Yes, thank you Dmitri, I think so too.
> Will come back to this later.
> TedvG
> 
> 
> 
> ted van gaalen
> 
> On 19 Mar 2016, at 08:46, Dmitri Gribenko <gribozavr at gmail.com <mailto:gribozavr at gmail.com>> wrote:
> 
>> Hi Ted,
>> 
>> Thank you for starting this thread.  I agree that removing the C-style
>> for loop has degraded the readability and clarity of some of numerics
>> code.
>> 
>> In the feedback to SE-0007 many people have said that they can convert
>> their code to for-in loops, but I think this actually means that in
>> code that is typically written in Swift today, loops primarily operate
>> on sequences and collections.  It means that numerics is a domain that
>> not many people work in.  But it is a very important domain
>> nevertheless, and clarity for numerics code matters at least as much
>> as it does everywhere else.
>> 
>> I think one way to approach this discussion would be to present
>> multiple concrete code samples that contain C-style for loops and are
>> awkward to write without them.  We can then try looking for patterns,
>> generalize and simplify, and discuss possible solutions.
>> 
>> Dmitri
>> 
>> -- 
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com <mailto:gribozavr at gmail.com>>*/
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list