docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0143: multi-axis index on a type indexed along one axis

An index with several parts and a slice among them (m[1:, 0]) gives one argument per axis. List, Slice, fixed arrays and str have one axis, so they take one part. Slice and index in separate brackets (m[1:][0]), or keep the data in an Array<T, N> (core::array::Array), which takes axis arguments. A type of your own takes them by implementing Index over a tuple of isize and core::index::SliceArg.

nabi
let xs = [10, 20, 30, 40];
let y = xs[1:, 0];
error[E0143]: `List<i64>` is indexed along one axis, but this index has 2 parts with a slice among them
  --> main.nabi:2:9
   |
 2 | let y = xs[1:, 0];
   |         ^^^^^^^^^
   |
   = help: slice and index in separate brackets (`m[a:b][c]`), or keep the data in an `Array` (`core::array::Array`), which takes `m[a:b, c]`

Slice first, then index the slice, or use an Array:

nabi
use core::array::Array;

let xs = [10, 20, 30, 40];
let y = xs[1:][0];
let m: Array<i64, 2> = [[1, 2], [3, 4]];
println(f"{y} {m[1:, 0]:?}");
20 [3]

Related: E0056 invalid indexing

Found a mistake? Edit this page on GitHub. Last updated