Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
derefr
on May 18, 2017
|
parent
|
context
|
favorite
| on:
Swift is like Kotlin
Is there a parse-time reason that they required the "_" syntax, rather than simply:
func greet(greeting: String, personName: String) { print("\(greeting), \(personName)!") }
thramp
on May 18, 2017
|
next
[–]
It's a side effect of labeled arguments. The caller would use the function greet as `greet(greeting: "Hello", personName: "Alice")`.
masklinn
on May 18, 2017
|
prev
[–]
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.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: