[swift-evolution] Compiler should generate code base on the functions that have default values

Jordan Rose jordan_rose at apple.com
Wed Jan 20 15:51:47 CST 2016


> On Jan 17, 2016, at 19:18 , 肇鑫 via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hi David,
> 
> You understanding is correct. 
> 
> There is only one thing I have to mention. Unless the other c style languages which you can call default values in the middle, Swift only allows you to call default values in the last. That makes you example:
> 
> func print(message: String = default, path: String = default, line: Int = default)
> 
> can only wrapped to 4 functions instead of 8.
> 
> func print(message: String, path: String, line: Int)
> func print()
> func print(message: String)
> func print(message: String, path: String)
> 
> You can't call func print(path: String) by calling func print(message: String = default, path: String = default, line: Int = default). print(_, path: "path"t, line: _) is not a valid calling in Swift.

This is not true.

func test(a a: Int = 0, b: Int = 1, c: Int = 2, d: Int = 3) {
  print("\(a) \(b) \(c) \(d)")
}
test()
test(a: 10)
test(b: 10)
test(c: 10)
test(d: 10)
test(b: 20, a: 10)
test(a: 10, b: 20, c: 30)
test(a: 10, d: 20)

All of these calls are legal.

Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160120/63411162/attachment.html>


More information about the swift-evolution mailing list