Skip to content

08 Named arguments ​

Calls with multiple arguments name the parameter receiving each value.

norm
Integer subtract(Integer left, Integer right) {
  return left - right
}

main() {
  Integer first = subtract(left: 9, right: 4)
  Integer reordered = subtract(right: 4, left: 9)
  Integer exchanged = subtract(right: 9, left: 4)

  printLine(first)
  printLine(reordered)
  printLine(exchanged)
}

Output:

text
5
5
-5

left: 9, right: 4 computes 9 - 4. The second call reverses the written order while preserving each label's value, so it still produces 5. The third call changes the value bound to each label and produces -5. Labels determine parameter binding; source order determines when the argument expressions are evaluated.

Try it: Give each argument a function call that prints a line, then observe evaluation order.

Precise rules: Language Reference.

Norm 0.25