[comp.lang.modula2] FOR LOOP indicies

ROSS@UCF1VM.BITNET (Brian) (07/06/90)

I personally like the way ADA (and supposidly Modula-3) handle FOR loops.
If you are going to restrict the type of the index variable for easy
compilation why not declare the variable at compilation time?
The type can be determined from the limits of the FOR loop.
And since it is an auto variable, its existance is limited to
scope of the FOR loop.
It should also be possible (but maybe not efficient) to check to see if
the memory location of the index has been changed, thus generating a
run-time error.



ross@ucf1vm.bitnet
ross@ucflan.cc.ucf.edu

pattis@cs.washington.edu (Richard Pattis) (07/06/90)

In article <INFO-M2%90070513582985@UCF1VM.BITNET>, ROSS@UCF1VM.BITNET (Brian) writes:
> I personally like the way ADA (and supposidly Modula-3) handle FOR loops.
> If you are going to restrict the type of the index variable for easy
> compilation why not declare the variable at compilation time?
> The type can be determined from the limits of the FOR loop.
> And since it is an auto variable, its existance is limited to
> scope of the FOR loop.
> It should also be possible (but maybe not efficient) to check to see if
> the memory location of the index has been changed, thus generating a
> run-time error.
> 

In fact, Ada compilers can and must check whether an attempt is made to
modify the value of a loop parameter inside the loop.  These are reported
as compile time errors.  The mechanism for checking should already exist in
Ada compilers, because one can declare runtime CONSTANTs (not know at
compile time; in fact, their values may be enterd by the user); these objects
also can be examined but not be changed in the scope of their declaration.

But if Modula-2 compiler writers must produce compilers that adhere to
all these extra semantic constraints that make Ada a better programming
language, then their compilers will get as huge and slow as Ada compilers.

Rich Pattis