Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Modula 3 > some thoughts a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 62 of 148
Post > Topic >>

some thoughts about PROCEDUREs

by Henning Thielemann <iakd0@[EMAIL PROTECTED] > Sep 2, 2003 at 06:42 PM

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?




 3 Posts in Topic:
some thoughts about PROCEDUREs
Henning Thielemann <ia  2003-09-02 18:42:25 
Re: some thoughts about PROCEDUREs
"Rodney M. Bates&quo  2003-09-03 00:22:31 
Re: some thoughts about PROCEDUREs
leeo@[EMAIL PROTECTED] (  2003-09-02 20:48:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 0:43:05 CDT 2008.