[swift-evolution] Streamlining closures

Andrew Brown a.br at me.com
Sun Dec 13 13:41:16 CST 2015


I've never really been able to read this naturally.
What opinions do people have on 
{ with variable do sequence }
Or 
with variable { sequences }

ABR.

> On 13 Dec 2015, at 15:03, Marc Knaup via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Compare the following cases:
> 
> #1
> for variable in sequence {}
> 
> #2
> someFunction({ variable in sequence })
> 
> Case #1 assigns elements from sequence to variable, so sequence is the SOURCE and variable is the DESTINATION.
> Case #2 has variable as SOURCE and sequence as DESTINATION (return value).
> It's flipped!
> It feels like it's meaning the same ("destination IN source") but it is not. That's inconsistent and confusing.
> 
> Changing #2 to the following breaks the inconsistency and avoids the confusion:
> 
> someFunction({ variable do sequence })
> 
> I know the example doesn't make much sense as it just returns the sequence and ignores the variable. But it's good enough to highlight the inconsistency.
> 
> 
>> On Sun, Dec 13, 2015 at 3:47 PM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>> 
>>> Am 13.12.2015 um 15:26 schrieb Marc Knaup <marc at knaup.koeln>:
>>> 
>>> I agree though that "in" is confusing and I never understood what "in" means here.
>>> Since "do" is no longer used for loops but code blocks it would make sense to replace "in" with "do“. 
>> 
>> Well, I read
>> 
>> { error in … }
>> 
>> as meaning, „error“ is bound within („in“) the following statements. I’m fine with that.
>> 
>> -Thorsten
> 
> 
> _______________________________________________
> 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/20151213/602e8141/attachment.html>


More information about the swift-evolution mailing list