
A7.2 Comparison 153
A7.2.4 Types
Gauss primarily has a matrix type. Ox is implicitly typed, and has the fol-
lowing types: integer, double, matrix,
string, array, file, function, class. Type is
determined at run time (and can change at
run time). E.g. a=1; creates an integer,
a=1.0; a double and a=<1>; amatrix.
A7.2.5 Matrix indexing
Indexing starts at 1, so m[1,1] is the first
element in a matrix. Vectors only need
one index. A matrix can be indexed by a
single index, a list of numbers, or an ex-
pression evaluating to a vector or matrix
(in which case no spaces are allowed). A
dot indicates all elements, for example:
w[1,1]
w[2:5,3:6]
w[1 3:4,.]
w[a+b,c]
Indexing starts at 0, so m[0][0] is the
first element in a matrix. Ox can be made
to start indexing at 1; this will lead to a
somewhat slower program. Vectors only
need one index. A matrix can be indexed
by a single index, a list of numbers, or
an expression evaluating to a vector or
matrix (including matrix constants) or a
range. The upper or lower index in a
range may be omitted. A empty index in-
dicates all elements, for example:
w[0][0]
w[1:4][2:5]
w[<0,2:3>][]
w[a + b][c]
w[:4][2:]
A7.2.6 Arrays
Gauss implements arrays using the varput
and varget function.
The array is a type in Ox, e.g. {"one",
"two", <1,2>} is an array constant,
where the first two elements are a string,
and the last a matrix. To print these:
print(a[0], a[1], a[2]).Anewar-
ray is created with the new operator.
Komentarze do niniejszej Instrukcji