Skip to content

77 Lexical references ​

&count borrows the writable local location as ref<Integer>; *target reads and replaces the stored value. The reference stays within the call and cannot escape as a return value.

norm
Void increment(ref<Integer> target) {
  *target = *target + 1
}

main() {
  Integer count = 3
  increment(target: &count)
  printLine(count)
}

Expected output:

text
4

Try it: Change increment to return ref<Integer> and add return target; the compiler rejects ref in a return type (NORM-TYPE-0001).

Precise rules: Reference.

Norm 0.25