Inconsistencies in use of tuple as function argument

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Inconsistencies in use of tuple as function argument

Boon Chew

In the code example below, notice that when tuple is used in a returned function, it is distinguishable from regular function arguments.  It seems like the semantic breaks down in this context - that is, user won't be able to tell if the function accepts a tuple or regular function arguments.

And when used in a regular function, a tuple needs to be passed in instead.  Why the inconsistencies?

func testFunctionUsingTuple()->(Int, String)->Void {
    func t
(x:(Int, String)) { 
        
print("\(x.0) \(x.1)") 
    
} 
    
return t 
} 

func testFuncUsingArgs
()->(Int, String)->Void { 
    func t
(x:Int, y:String) { 
        
print("\(x) \(y)") 
    
}
    
return t 
} 

do { 
    
var t = testFunctionUsingTuple() 
    t
(1, "test") 
} 

do { 
    
var t = testFuncUsingArgs() 
    t
(1, "test") 
} 

func funcUsingTuple
(x:(Int, String)) { 
    
print("\(x.0) \(x.1)") 
} 

func funcUsingArgs
(x:Int, _ y:String) { 
    
print("\(x) \(y)") 
} 

funcUsingTuple
(1, "test") // Won't work - need to use funcUsingTuple((1, "test")) instead 
funcUsingArgs
(1, "test3")

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/c3f5f19f-ea9d-4fb1-b525-811eb4a157c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.