[Oberon] Procedure variables and local procedures
Jörg
joerg.straube at iaeth.ch
Sat Sep 30 09:23:10 CEST 2017
Wojtek
> I am guessing that Chris has the above in mind. I second his opinion: without the dynamic arrays (or "open arrays") the language is crippled.
Oberon-07 has open arrays.
Open arrays are formal parameters whose length is not known at compile time.
Here an example in Oberon-07:
PROCEDURE Max(v: ARRAY OF REAL): REAL; (* ‚v‘ is an open array *)
VAR i: INTEGER; max: REAL;
BEGIN
max := v[0];
FOR i := 1 TO LEN(v)-1 DO IF v[i]>max THEN max := v[i] END END
RETURN max END Max;
and use Max() with vectors of different lengths like
v1: ARRAY 10 OF REAL;
v2: ARRAY 88 OF REAL;
If you would like to write a library operating on two dimensional matrices, you can do so in Oberon-07. It is left as an exercise how to implement
MODULE Matrix;
TYPE
Matrix* = POINTER TO MatrixDesc;
MatrixDesc = RECORD
m*: PROCEDURE (i, j: INTEGER): REAL (* m(i, j) returns an elem of the matrix *)
END;
PROCEDURE Allocate*(m: Matrix; dim1, dim2: INTEGER);
PROCEDURE Initialize*(m: Matrix; f: Files.File);
PROCEDURE EigenValue*(m: Matrix): REAL;
END Matrix.
As all this is possible in Oberon-07, I was wondering what dynamic arrays are.
br
Jörg
More information about the Oberon
mailing list