[comp.lang.modula2] type of limit expressions of FOR loops

Barry_Cornelius@durham.ac.UK (04/12/88)

Harvard Townsend recently communicated about the types of the
expressions used in a FOR statement.

Suppose that we are dealing with the FOR statement:
      FOR v := A TO B BY C DO SS END
The original definition of Modula-2 (see, for example, page 154 of the
2nd edition of "Programming in Modula-2" (PIM)) states:
      "A and B must be assignment compatible with v".

However, it was pointed out that the comparison of the control variable
and the final value is difficult to implement when one is of type INTEGER
and the other is of type CARDINAL.   Hence, in the 3rd edition of PIM
(page 158), Wirth has:
      "A and B must be compatible with v".
Thus, according to this definition, the mixing of INTEGER and CARDINAL
is not allowed.

Subsequently, it has been argued that this change need only have been made
for the final value, i.e.,
      "A must be assignment compatible and B must be compatible with v".

Currently, the standardisation groups have a position which agrees with
the 3rd edition of PIM.
==
Barry Cornelius
==
Address:
   Computer Science Group, School of Engineering and Applied Science,
   University of Durham, Durham, DH1 3LE, England
Telephone:
   My office: Durham (091 or +44 91) 374 2638
   Secretary: Durham (091 or +44 91) 374 2630
   Fax:       Durham (091 or +44 91) 374 3740
Electronic Mail Addresses:
   JANET:       Barry_Cornelius@uk.ac.dur.mts
   Internet:    Barry_Cornelius%mts.dur.ac.uk@cunyvm.cuny.edu
   UUCP:        ...ukc!cs.nott.ac.uk!bjc
   BITNET/EARN: Barry_Cornelius%DUR.MTS@AC.UK

firth@sei.cmu.edu (Robert Firth) (04/12/88)

Just to add a random comment here:  wouldn't it be a good
idea to change Modula-2 so that the control variable is
LOCAL to the FOR-statement, as it is in Algol-68, BCPL, and
Ada.

First, that would get rid of the pathologies about compatibility
of the start, stop and step expressions - you could just say
that the variable is of a host type with enough range to encompass
the entire iteration range.

Secondly, it would remove about 12 PAGES of VDM in the draft
standard, that try (almost successfully) to define what it
means to "threaten" the control variable.  A major simplification,
I believe.