> Le 8 juin 2017 à 05:15, Susan Cheng via swift-evolution 
> <[email protected]> a écrit :
> 
> Just a thought
> 
> if parentheses is important, why the tuples are not?
> 
> var tuple1: (Int, Int) = (0, 0)
> var tuple2: ((((Int, Int)))) = (0, 0)
> 
> type(of: tuple1) == type(of: tuple2)    // true
> 
> var void: ((((((())))))) = ()
> 
> type(of: void) == type(of: Void())  // true

I think is is because Swift doesn't have tuples with a single value: those 
parenthesis are just parenthesis around an expression:

    let a = 1 + 2
    let b = (1 + 2)
    let c = (1 + 2) * 3
    let d = ((1 + 2)) * 3

Many languages behave like that, Swift is no exception.

It also allows some fancy/legacy/foreign programming styles :-)

    // C-style if
    if (a && b) {
        ...
    }
    // "return function"
    return(a && b)

Languages that have single-valued tuples need a special syntax so that they are 
distinguished from parenthesised expressions. In Python, this is a trailing 
comma:

    1    # 1
    (1)  # 1
    (1,) # (1,)

Swift currently disallows trailing commas inside parenthesis.

Gwendal

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to