[Pitch] Improving capturing semantics of local functions

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

    foo()
    ...
}

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

    foo()
    ...
}

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

Mike

···

on Tue, 21 Nov 2017 11:06:04 +0100 Tino Heth <2th@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.

1 Like

or even this:

{
    weak capture foo, loo, poo
    unowned capture bar, baz, booz
    weak capture delegate = self.delegate!

    // capture list if any has to be before anything else

    weak var some = other
    foo()
    ...
}

here "capture" is a noun, playing the role of "var" / "let".

Mike

···

On 21 November 2017 at 21:55, Mike Kluev <mike.kluev@gmail.com> wrote:

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

    foo()
    ...
}

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

    foo()
    ...
}

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