In the last article on FreshMarker Ranges, the Right-limited Exclusive Ranges and Length-limited Ranges were introduced. They were not part of the FreshMarker Ranges support for quite some time.
Previously, it was only possible to create regular ranges with the Length-limited Ranges syntax, i.e. ranges that represent monotonically increasing sequences.
1..*5 // 1, 2, 3, 4, 5
The reason is simply illustrated in the example above. On the left is the lower limit and behind the *
is the number of elements in the range. These two values cannot be used to define a monotonically decreasing sequence. Instead, there are two other possible definitions for inverse Length-limited Ranges.
5*..1 1..*-5 // 1, 0, -1, -2, -3
In the first variant, the upper limit is defined on the right and the number of elements on the left. The second variant uses the popular trick of using negative numbers to give a parameter additional meaning.
The second variant has now been implemented for FreshMarker, as it was very easy to integrate. Only an additional case distinction was required for a negative parameter. To be honest, I only thought of the first variant now while writing this article.
Inverse ranges can also not be specified for Right-unlimited Ranges. In this case, the reason is that there is no right parameter at all.
1..
At this point, various variants for an extended syntax could be tried out. But so far I have not found a satisfactory syntax. The shortlist currently includes only 1..-∞
with the additional counterpart 1..∞
for a regular Rght-unlimited Range.
But perhaps I’ll save myself the trouble at this point, because an approximation to an inverse Right-unlimited Range is simply a sufficiently large inverse Right-limited Range.
1..-2000000000
Not everything that is possible has to be implemented.