Anvil | Smiths Smiths | Register Register | Login Login |
Search:
Show links Show tools Show tree | Previous document Next document | njet.org > Anvil > Documentation > Language reference > Expressions > Assignments

Assignments

Assignment is a top-level expression: it cannot be nested using parenthesis. The target of assignment can be identifiers (pointing to variable, others than constants), attribute reference, subscriptions or empty subscriptions (append). There can be multiple targets, in which case the right-most expression is enumerated and values generated by enumeration are assigned in the given order to the target expressions on the left side. If enumeration ends before all the targets have values assigned, undefined is used.

Assignment can also take augmentation, meaning that the original value is modified with augmenting operator. Modification requires both a get and set operation for attributes and subscriptions. Empty subscriptions cannot be augmented, as they do not contain any value by default.

Augmentation operators are addition (+=), substraction (-=), multiplication (*=), division (/=), remainder (%=) and concatenation (&=), and they behaviour is similar to binary aritmethic operators.

Assign-if-undefined operator (?=) assign values to left side targets only if the current value of target is ``undefined´´. This operation is useful for initializing variables.

The right-most expression is an expression list, so it can contain multiple values separated with commas, generating ``anvil.lang.tuple´´.

  assignable-expr := ["&"] identifier accessor 
  assign-target   := assignable-expr 
  assign-targets  := assign-target ("," assign-target ) * 
  assignment      := assign-targets "=" expr-list 
  assignment      := assign-targets "+=" expr-list 
  assignment      := assign-targets "-=" expr-list 
  assignment      := assign-targets "*=" expr-list 
  assignment      := assign-targets "/=" expr-list 
  assignment      := assign-targets "%=" expr-list 
  assignment      := assign-targets "&=" expr-list 
  assignment      := assign-targets "?=" expr-list 
See also  | Refs  | Assignable primaries
Contributes notes:
2002-11-22  
Add a note
What's new | Anvil