On this page:
mutable
:  =
8.12

6.10 Mutable Variables and Assignment🔗ℹ

binding operator

mutable id maybe_annot

 

maybe_annot

 = 

:: annot

 | 

:~ annot

 | 

ϵ

Binds id so that its value can be changed using an assignment operator such as :=.

If an annot is present using ::, then the value of every assignment to id must satisfy the annotation, and the value installed into id is the converted value if annot is a converter annotation. Static information from annot is associated with uses of id whether attached by :: or :~.

> def mutable count = 0

> count := count + 1

> count

1

> count := "string"

> def mutable count :: Int = 0

> count := count + 1

> count := "string"

count: value does not satisfy annotation

  value: "string"

  annotation: Int

expression

id := expr

An assignment operator that changes the value of id to the result of expr and returns #void. The id must be bound with mutable.

The := operator is also recognized by other forms, such as . and #%index, for changing mutable components of some values.

> def mutable count = 0

> count := count + 1

> count

1