Y
Hacker News
new
|
ask
|
show
|
jobs
by
derefr
3312 days ago
Is there a parse-time reason that they required the "_" syntax, rather than simply:
func greet(greeting: String, personName: String) { print("\(greeting), \(personName)!") }
2 comments
thramp
3312 days ago
It's a side effect of labeled arguments. The caller would use the function greet as `greet(greeting: "Hello", personName: "Alice")`.
link
masklinn
3312 days ago
The reason is that named parameters is the default, so in your case greeting and personName are both "internal" and "external" names. "_ greeting" sets the external name to _ (aka positional) and the internal name to "greeting" instead.
link