Cold Help System: Programming: ColdC Reference Manual: Language Structure: Expressions: Operators: Assignments: Scatter


In a scatter assignment multiple variables are specified within a square brackets on the left, and each element from the list expression on the right is assigned to the respective variable on the left, with any remaining elements in the list being discarded. For example:

[var1, var2, var3] = ["this", ["for"], 1, 'that]

In this example var1 is assigned the string "this", var2 is assigned the list ["for"], var3 is assigned the integer 1 and the remaining symbol 'that is discarded.

The remaining elements may all be grouped in a new list which is stored in the last variable by using the List Splice operator on the last variable in the scatter list, such as:

[var1, var2, @var3] = ["this", ["for"], 1, 'that]

In this example var3 would have the value [1, 'that]. The List Splice operator may only be used this way on the last variable in the scatter list.

Scatter Assignments may also be nested, assuming the list expression is a nested list in the same order as the scatter list. For example:

[var1, [var2, @var3], var4] = ["this", ["for", 1, 2, 3], 'that]

In this example var1 is assigned "this", var2 is assigned "for", var3 is assigned the new list [1, 2, 3] and var4 is assigned the remaining symbol 'that.


Simple | Scatter | Dual | Default


the Cold Dark