Group Assignments

Rittle has a very specific feature allowing multiple assignments to be made within a single statement.

In some examples:

**var small ***x, y, z*** = ***-1*;

This will declare “*x*”, “*y*”,
and “*z*”, and will assign value -1 to __all__ of them.

**var small ***x, y, z*** = ***-1, -2, -3*;

This will declare “*x*”, “*y*”,
and “*z*”, and will assign value -1 to ”*x*”,
value -2 to “*y*”, and value -3 to “*z*”.

There is also the possibility to skip the initialisation of some variables, while skip assigning values to the others:

**var small ***x, y, z*** = ***-1, , -3*;

This statement will still initialise “*x*”
and “*z*” but will do nothing about “*y*”.

The same is valid in statements outside of declaration, as well as other variables, functions, and expressions. Even reusing variables within the same statement is allowed:

**x, y, z = foo(1,2), (a+1), (y-2);**

In the most general case any number of variables can be sequentially initialised with any number of values as long as the number of values is not greater than the number of variables to be initialised. If the number of values is smaller than the number of variables, all remaining variables will be initialised with the last value from the list of initialising values.

Since the assignment is performed sequentially, it is possible to use group assignment to perform various programming “tricks”:

**x, y = y, x; ***‘ swap the values of x and y without using a
third variable*

**a, b, c = b, c, a;*** ‘ rotate values in three variables*

* *