Trimmer

Meaning

A trimmer is used to refer to a subset of values in a multiple’s dimension while slicing. For example, in the slice:slice

foo[1:5]

The trimmer 1:5 refers to the values with index 1 to 5 in the only dimension of the multiple foo. The action of applying a trimmer is known as trimming, and it always yields a slice.

The multiple resulting from the slice above will have lower bound 1 an upper bound 5, but it is possible to “rebound” the result of trimming by using revised bounds. Consider:

[]int foo = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
[]int trim1 = foo[6:10];
[]int trim2 = foo[6:10 at 1];
[]int trim3 = foo[6:10 @ 1];

Where trim1 has lower bound 6 and upper bound 10, and both trim2 and trim3 have lower bound 1 and upper bound 5. All trim1, trim2 and trim3 contain values 6, 7, 8, 9, 10. Note that at and @ are alternative representations of the “at token”.

All components of a trimmer are optional. If the lower bound of the trimmer is omitted (as in [:5]) then it defaults to the lower bound of the multiple’s dimension. If the upper bound of the trimmer is omitted (as in [1:]) then it defaults to the upper bound of the multiple’s dimension. Both bounds can be omitted, resulting in : or simply an empty string, such as in the slice foo[2,]. If the lower bound revision part is omitted, the bounds of the resulting multiple are the same than the bounds specified in the trimmer (or implied by the trimmer.)

Syntax

Simplified [RR 5.3.2.f,g]:

f) trimmer : lower bound option, up to token, upper bound option,
             revised lower bound option.
g) revised lower bound : at token, lower bound.

See Also