^k counts from the end of the collection being indexed, so it has a meaning
only where an index reads it: as the index itself, as a bound of a slice, or
as the argument of get — and only on a collection that has an end (an
array, a tuple or a string).
let last = ^1
// ^^ error[TE157]
let ages = #{ "ana": 31 }
print(ages[^1])
// ^^ error[TE157]: a map has no endFix it¶
Write the count where the index is:
let xs = [10, 20, 30]
print(xs[^1]) // 30
print(xs[..^1]) // [10, 20]
print(xs.get(^3)) // 10To keep a from-the-end position in a variable, keep the count and apply ^
at the index: let k = 1 then xs[^k].