Anonymous user
Named parameters: Difference between revisions
→{{header|Swift}}
Line 1,499:
Swift has local and external (named) parameters.
▲<lang Swift>func isGreater(#x:Int, thanY y:Int) -> Bool {
return x > y
}
assert(isGreater(x: 5, thanY: 10) == false)</lang>
If you do not want the caller to specify parameter names, explicitly use <code>_</code> as external parameter name:
<lang Swift>func isGreater(x:Int, _ y:Int) -> Bool {
return x > y
}
assert(isGreater(5, 10) == false)</lang>
Note that when you don't explicitly specify external parameter names, the behavior is different for functions, methods and initializers:
* For a function or method, the first parameter doesn't have an external parameter name by default (as if you used <code>_</code>) unless you specify it; the rest of the parameters
* For an initializer, all parameters
=={{header|Tcl}}==
|