Trying to understand by
from the examples
#1427
-
Hi! thanks a lot for the effort you are putting in this language, it looks fantastic!
Note the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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:
You can use All of these rules have been shamelessly copied from Swift. |
Beta Was this translation helpful? Give feedback.
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:
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 forfun(x x: Int)
.All of th…