[swift-evolution] [Review] SE-0066: Standardize function type argument syntax to require parentheses

Vladimir.S svabox at gmail.com
Wed Apr 27 07:16:11 CDT 2016


 > But keep away from closure expressions, please! There is nothing ambiguous
 > there.

Really?

func z1(block: (Int,Int) -> Void) {
     block(1,2)
}

z1 { x, y in print(x,y)} //
z1 { x in print(x.0, x.1)} // ???
z1 { (x, y) in print(x, y)} //

func z2(block: ((Int,Int)) -> Void) {
     block((1,2))
}

z2 { x, y in print(x,y)} // ???
z2 { x in print(x.0, x.1)}
z2 { (x, y) in print(x, y)} // ???
//z2 { ((x, y)) in print(x, y)}  // compilation error

// this will compile, but
runtime error
let ft : (Int,Int) -> Void = { x in print(x)} // hm..
ft(1, 2)

On 27.04.2016 11:53, Thorsten Seitz via swift-evolution wrote:
> I am strictly against requiring parentheses in closure expressions.
> Parentheses are visual clutter if not really needed and for a closure
> expression there is no need for parentheses as the parameter list is
> already nicely bracketed by `{ ... in`.
> Actually I would argue that parentheses around parameter lists in closure
> expressions should be prohibited for that reason.
>
> I'm not fond of requiring parentheses around single non-tuple parameters in
> type declarations either but I could probably grudgingly live with that change.
> But keep away from closure expressions, please! There is nothing ambiguous
> there.
>
> -Thorsten
>
>
> Am 27. April 2016 um 00:07 schrieb David Owens II via swift-evolution
> <swift-evolution at swift.org>:
>
>>
>>> On Apr 26, 2016, at 1:31 PM, Chris Lattner <clattner at apple.com
>>> <mailto:clattner at apple.com>> wrote:
>>>
>>>
>>>> On Apr 25, 2016, at 11:28 PM, David Owens II via swift-evolution
>>>> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>
>>>> *What is your evaluation of the proposal?
>>>> *
>>>> I reluctantly agree with the proposal with the following caveat: I do
>>>> not agree with the rationale to support being able to choose to
>>>> omit the () for the parameter list of the closure declaration.
>>>>
>>>> I see no cohesive argument that says that the parens should be required
>>>> in some cases but not in others when talking about parameter lists.
>>>>
>>>> I believe the proposal should be amended that the following should be
>>>> the only allowable forms:
>>>
>>> Hi David,
>>>
>>> To be clear, this proposal is not about changing closure expressions, it
>>> was just a FAQ, and the section at the end is simply my personal
>>> opinion.  Changing closure expression syntax would be a separate proposal.
>>
>> My argument is changing the parameter list in one context but not the
>> other is only solving one of the potentially ambiguous use cases instead
>> of the general case. My opinion is they should be changed as the same
>> time if they are going to be changed at all.
>>
>> -David
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>


More information about the swift-evolution mailing list