[swift-evolution] [Pitch] Improving capturing semantics of local functions

Mike Kluev mike.kluev at gmail.com
Tue Nov 21 15:55:31 CST 2017

on Tue, 21 Nov 2017 11:06:04 +0100 Tino Heth <2th at gmx.de> wrote:

> > 5. func fn<T>[foo, bar](param: T) throws -> T where T: Equatable
> captures [foo, bar] { … }
> I guess it can be considered good practice to start a line with the most
> important information, and move the details to the far right, so that they
> don’t distract the hasty reader.
> I’m not sure if the capture list an example for this, but for good or
> worse, it didn’t draw much attention in another position either (the first
> „[foo, bar]“ that slipped through).
> That variant (func fn<T>[foo, bar](param: T)) is definitely my favorite,
> because it keeps a characteristic of closures (first the capture list, then
> the parameters), but doesn’t carry over the mingling of body and parameters
> that has to be done in closures.

maybe this?

    capture weak foo, loo, poo         // "capture list", if present
    capture unowned bar, baz, booz   // shall be at the beginning
    capture weak delegate = self.delegate!  // before anything else


compare to the current:
        weak foo, weak loo, weak poo
        unowned bar, unowned baz, unowned booz
        weak delegate = self.delegate!
    ] in


a bit more explicit / expressive, looks like ordinary statements, and
doesn't have that strange "in" at the end.

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

More information about the swift-evolution mailing list