Skip to content

Trying to understand by from the examples #1427

Answered by kyouko-taiga
avillega asked this question in Q&A
Discussion options

You must be logged in to vote

Those are argument labels and they are part of a function's (or subscript's) API. When you declare a function, for each parameter you get to specify an argument label, which must be used at call site, and a parameter name, which is used in the body of the function. Those can be distinct:

fun foo(label name: Int) {
  // here we must use `name`
}

fun bar() {
  foo(label: 1) // here we must use `label`
}

You can use _ to specify that there is no label at call site, as in the example you presented. Finally, as a shorthand, you can omit the label in the declaration, in which case it gets the same value as the parameter name. In other words, fun f(x: Int) is short for fun(x x: Int).

All of th…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by avillega
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants