[swift-evolution] Streamlining closures

Marc Knaup marc at knaup.koeln
Sun Dec 13 09:03:23 CST 2015


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/29172338/attachment.html>


More information about the swift-evolution mailing list