[comp.lang.modula2] types of the limit expressions of FOR statements

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

Robert Firth raises the issue of the scope of the control variable.
The BSI and ISO standardisation working groups consider any change
to make the control variable of a FOR statement a local
variable/constant of the FOR statement too radical a change to the
language.

However, the issue previously under discussion concerned whether the
limit expressions are compatible/assignment-compatible with the
control variable.   The issue about the scope of the control variable
is a SEPARATE issue.   (* This compatibility problem doesn't go away
by changing the scope of the control variable *)
==
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

woolsey@nsc.nsc.com (Jeff Woolsey) (04/15/88)

While we're on the subject of FOR statements and limits, fill in the
blank below with something that will make the loop execute 26 times.

MODULE Poser;

FROM somewhere IMPORT something;

VAR 
  ch: CHAR;

BEGIN
  FOR ch := 'Z' TO 'A' BY _____ DO
    something(ch)
  END
END Poser.

seitz@cory.Berkeley.EDU (Matthew Eric Seitz) (04/17/88)

In article <5035@nsc.nsc.com> woolsey@nsc.UUCP (Jeff Woolsey) writes:
>While we're on the subject of FOR statements and limits, fill in the
>blank below with something that will make the loop execute 26 times.
>
>MODULE Poser;
>
>FROM somewhere IMPORT something;
>
>VAR 
>  ch: CHAR;
>
>BEGIN
>  FOR ch := 'Z' TO 'A' BY _____ DO
>    something(ch)
>  END
>END Poser.

	I'm not even sure that the index variable can be of type CHAR.  The
definition of FOR on p. 158 of _Programming_In_Modula-2_, it seems to imply
that the index for a FOR statement must of type INTEGER or CARDINAL.  This
is because it defines the value of the index in terms of the "+" operator,
which applies only to operands of type INTEGER, CARDINAL, or REAL, and of
the step value, which must be of type INTEGER or CARDINAL ( "A, A+C,
A+2C" ). 

	On the other hand, on p. 162 Wirth defines INC( x, n ) as x := x + n,
but then adds that if x is of type CHAR or an enumeration type x is replaced
by the n-th successor of x.  Under this interpretation, and assuming that if
n < 0 x is replaced by the ABS(n) predecessor of x, you should be able to
fill the blank with -1.  Similarly, you can interpret a step value < 0 as
equivalent to DEC( x, n ) with the same results.

					Matthew Seitz
					seitz@cory.berkeley.edu