Navigation
Synopsis Assign a value to a variable or more complex data structure.
Syntax Assignable AssignmentOp Exp

where AssignmentOp may be one of =, +=, -=, *=, /=, or ?=.

An Assignable is one of the following:
  1. Var
  2. Assignable [ Exp ]
  3. Assignable [ Exp .. Exp ]
  4. Assignable [ Exp, Exp .. Exp ]
  5. Assignable . Name
  6. < Assignable, Assignable, ..., Assignable >
  7. Assignable ? Exp
  8. Assignable @ Name
  9. Name ( Assignable, Assignable, ... )
Description The purpose of an assignment is to assign a new value to a simple variable or to an element of a more complex data structure.

The standard assignment operator is =. The other assignment operators can be expressed as abbreviations for the standard assignment operator.
Assignment Operator Equivalent to
Assignable += Exp Assignable = Assignable + Exp
Assignable -= Exp Assignable = Assignable - Exp
Assignable *= Exp Assignable = Assignable * Exp
Assignable /= Exp Assignable = Assignable / Exp
Assignable &= Exp Assignable = Assignable & Exp
Assignable ?= Exp Assignable = Assignable ? Exp


An assignable is either a single variable, (the base variable), optionally followed by subscriptions, slices or field selections. The assignment statement always results in assigning a completely new value to the base variable. We distinguish the following forms of assignment:
  • Variable: Assign to a variable.
    • Subscription: Assign a single element of a structured value.
      • Slice: Assign to a slice of a list or string.
        • Field: Assign to a field of a tuple, relation or datatype.
          • Multiple: Assign to multiple assignables.
            • IsDefined: Assign but replace if value is not defined.
              • Annotation: Assign to annotation.
                • Constructor: Assign to constructor.
                  Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.