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

Mike Kluev mike.kluev at gmail.com
Wed Nov 22 08:10:18 CST 2017


On 21 November 2017 at 21:55, Mike Kluev <mike.kluev at 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.
>
>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171122/c7e334fc/attachment.html>


More information about the swift-evolution mailing list