[swift-evolution] Lambda function syntax
Brent Royal-Gordon
brent at architechies.com
Wed Dec 23 07:58:11 CST 2015
> I think => may be confusing in many of shown cases. Its a cause/efect symbol and can be also and operator.
>
> I put again the idea of with for the newcomers:
>
> with ( parameters ) -> return_type {
> statements
> }
>
>
> sorted = names.sort( with(s1, s2){ s1 > s2 } )
>
> sorted = names.sort( with{ $0 > $1 } )
>
>
> sorted = names.sort() with { $0 > $1 }
>
> reversed = names.sort with(s1,s2){
>
> //bla bla code
> return resultVar
> }
>
> reversed = names.sort with { $0 > $1 }
I don't think this is particularly helpful. Even if you don't know what a closure is, if you're familiar with any C-like language, or with other parts of Swift's syntax, you know that `{ ... }` indicates a piece of code. That's all you really need to know in order to understand what `names.sort { $0 > $1 }` *means*, even if you don't immediately know how it *works*.
We don't need a keyword hopping up and down shouting "CLOSURE! CLOSURE! CLOSURE!"; all we need is a syntactic marker delimiting the boundary between the parameter list and whatever's adjacent to it. Your `with` and `delegating` keywords hop up and down. The current `in` keyword marks the boundary; so does whatever we actually call my proposed `=>` symbol. (Again, I don't actually like that specific symbol—think of it as a placeholder.)
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list