Here is another philosophic consideration of Modula 3 syntax: :-)
I wondered why procedure bodies contain an equal sign '=' before the
BEGIN, e.g.
PROCEDURE Min (x, y: INTEGER):INTEGER =
BEGIN
IF x<y THEN RETURN x ELSE RETURN y END;
END Min;
I assumed that this may be due to the analogy to constant definitions. Of
course a procedure body is like the contents of an array constant. But
following the syntax of declarations of initialized arrays and records we
had to write:
CONST
Min = PROCEDURE (x, y: INTEGER):INTEGER {
BEGIN
IF x<y THEN RETURN x ELSE RETURN y END;
END
}
A procedure declaration in an interface would transform into something
like
TYPE MinProc <: PROCEDURE (x, y: INTEGER):INTEGER;
CONST Min : MinProc;
One still had to find a solution for local procedures.
It is even possible to go one step further: PROCEDURE and ARRAY are very
similar. In the mathematical sense they are mappings. They only differ in
the implementation: PROCEDUREs employ some computations to get the results
whereas ARRAYs stores all possible results simultanously. The input
arguments of a PROCEDURE are like indices of an ARRAY and can be perfectly
collected in a RECORD. This would look like:
TYPE
MinArgs = RECORD x, y: INTEGER END;
MinProc = PROCEDURE MinArgs OF INTEGER;
(* or just *)
MinProcI = PROCEDURE RECORD x, y: INTEGER END OF INTEGER;
(* the same signature in ARRAY form *)
MinArr = ARRAY INTEGER OF ARRAY INTEGER OF INTEGER;
Nice, isn't it?


|