[swift-evolution] For-loop revisited

Ted F.A. van Gaalen tedvgiosdev at gmail.com
Fri Feb 26 17:31:04 CST 2016


Thanks for clarifying, David

However, to me, it still remains awkward and indirect to 
use collections in cases where they are not necessary at all. 

About reserved words: 
The sub-keywords  (‘from’, ‘to’, and ‘by’)  
are context dependent and will almost certainly 
not be used on their own, rather always together
with a primary keyword.

An advanced compiler should be able to
determine from the context of a statement 
if words used in that statement act as keywords or not! 

For instance the PL/1 language from < 1970 , far ahead of its time,  **1**
in spite of being very extensive, has no reserved words at all.

Most people will not use reserved words as identifiers because this is confusing.  

I will write a Swift proposal next week for
for .. from .. to.. [by.. ] ,
in spite of all of its functionality being 
already present in the classical for ;; loop.  

I still cannot find a reason why it should be removed.
As with any other language construct,
it really depends on how one uses it.
Like with any other language elements in Swift,
it’s very easy to create a mess, no one can prevent this.

Of course, I would use a  for..in.. 
if dealing with a collection: using a 
classic for ;;  for that is clearly not an advantage.

TedvG



  **1**    As a source of inspiration, one might find this interesting:
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI#Looping_Statements

Ted

> On 26.02.2016, at 21:52, David Waite <david at alkaline-solutions.com> wrote:
> 
> 
>> On Feb 26, 2016, at 9:07 AM, Ted F.A. van Gaalen via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>>> Does .stride(), which in the end uses a descendant of SequenceType, just calculate a new value each time   for..in..   uses .next() on this collection? 
> 
> this.
> 
>>    for  x from xmin to xmax by xstep  { }
>> 
>>    for x from xmax to xmin by -xstep  { } 
>> 
>>    for apple from 1 to applesInTruck  { }
>> 
>> No need for collections in these cases,
> 
> As the thread for removal of C-style for showed in benchmarks, using a range or stride does not have a performance impact under optimization. Such new syntax would need to stand on its own as a second alternative to using ranges/strides. 
> 
> Considering that it would require reserving three new keywords (‘from’, ‘to’, and ‘by’) this will be a hard argument to make.
> 
> -DW
> 

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


More information about the swift-evolution mailing list