Skip to content

09 Default arguments ​

A parameter with a default supplies a value when its caller omits that label.

norm
String greet(String name, String punctuation = "!") {
  return "Hello, " + name + punctuation
}

main() {
  String ordinary = greet(name: "Norm")
  String question = greet(name: "Norm", punctuation: "?")

  printLine(ordinary)
  printLine(question)
}

Output:

text
Hello, Norm!
Hello, Norm?

punctuation defaults to "!" in the first call. The second call explicitly supplies "?". The body sees a String either way; the default is part of the function declaration's call contract.

Try it: Change the default to "." and observe which call changes.

Precise rules: Language Reference.

Norm 0.25