
154 Appendix A7 Comparing Gauss and Ox syntax
A7.2.7 Declaration and constants
In Gauss, a variable can be assigned a
value with a let or implicit let state-
ment. If the variable doesn’t exist yet,
it is declared, otherwise it is redeclared.
A variable can be declared explicitly with
the declare statement. Assignment in
a let statement may consist of a number,
a sequence of numbers (or strings) sepa-
rated by spaces, or numbers in closed in
curly brackets. The latter specifies a ma-
trix, with a comma separating rows, and
a space between elements in a row (these
are not proper matrix constants, because
they cannot be used in expressions). A
variable outside a function is also created
if a value is assigned to it (and it doesn’t
exist yet).
letw={111};
let y0 = 1 2;
let y1[2,2] = 1 1 2 2;
y2[2,2] = {1 1, 2 2}; /*(1)*/
let w[2,2] = 1;
let w[2,2];
w = zeros(2,2);
The line labelled (1) is an implicit let
which creates a 2 × 2 matrix. A state-
ment like y2[2,2] = 1; on the other
hand puts the value one in the 2,2 posi-
tion of y, which therefore must already
exist.
Ox has explicit declaration of variables.
A value can be assigned to a variable at
the same time as it is declared. If the vari-
able has external scope (i.e. is assigned
outside any function), you can use con-
stants only, (matrix or other constants).
Such constants can also be used in ex-
pressions.
decl w = < 1,1,1 >;
decl y0 = <1,2>;
decl y1 = <1,1; 2,2>;
decl y2 = <1,1; 2,2>;
decl w[2][2] = 1;
decl w[2][2];
decl w = zeros(2, 2);
/* only inside function */
If all statements would be used together,
the compiler would complain about the
last three declarations: w was already de-
clared earlier (no redeclaration is possi-
ble, but re-assignment is, of course). The
last declaration involves code, and can
only be made inside a function.
A7.2.8 Expressions
Assignment statements are quite similar,
e.g. y=a.*b+3-d;works in
both Gauss and Ox, whether the variables
are matrices or scalars.
Ox allows multiple assigments, e.g. i=
j=0;. In addition there are conditional
and dot-conditional expressions.
Commentaires sur ces manuels