[M3devel] Dynamic open array question
Martin Bishop
martinbishop at bellsouth.net
Thu Feb 26 04:35:46 CET 2009
I have this code:
MODULE Callback EXPORTS Main;
IMPORT IO, Fmt;
TYPE CallBack = PROCEDURE (a: CARDINAL; b: INTEGER);
Values = ARRAY [1..5] OF INTEGER;
VAR sample := Values{5, 4, 3, 2, 1};
callback := Display;
PROCEDURE Display(loc: CARDINAL; val: INTEGER) =
BEGIN
IO.Put("array[" & Fmt.Int(loc) & "] = " & Fmt.Int(val * val) & "\n");
END Display;
PROCEDURE Map(values: Values; worker: CallBack) =
BEGIN
FOR i := FIRST(values) TO LAST(values) DO
worker(i, values[i]);
END;
END Map;
BEGIN
Map(sample, callback);
END Callback.
This code works just fine, but I was thinking of making the array a
dynamic open array, but I couldn't figure out what I needed to change.
I tried making Values have the type REF ARRAY OF INTEGER and then
calling NEW inside of Map(), but I couldn't figure out how to use an
array constructor (since Values{5, 4, 3, 2, 1} would complain when
Values was a reference type).
More information about the M3devel
mailing list