[swift-evolution] Compiler should generate code base on the functions that have default values
zhaoxin肇鑫
owenzx at gmail.com
Wed Jan 20 19:03:08 CST 2016
You are right. I didn't know it can do that way.
There is a note in Swift document
<https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html>
.
NOTE
> Place parameters with default values at the end of a function’s parameter
> list. This ensures that all calls to the function use the same order for
> their nondefault arguments, and makes it clear that the same function is
> being called in each case.
It makes me think what I did.
zhaoxin
On Thu, Jan 21, 2016 at 5:51 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>
> 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/20160121/6ffaf2e6/attachment.html>
More information about the swift-evolution
mailing list