Skip to content
ZOLO / TE157 Type · error

`^k` outside an index position

Compiler diagnostic TE157: `^k` outside an index position.

^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 end

Fix 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))      // 10

To keep a from-the-end position in a variable, keep the count and apply ^ at the index: let k = 1 then xs[^k].

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

en