comp.lang.ada
 help / color / mirror / Atom feed
From: John.Goodenough@SEI.CMU.EDU
Subject: Re: FOR Iteration Scheme
Date: 19 Jul 88 13:52:08 GMT	[thread overview]
Message-ID: <8807191352.AA07439@cs.sei.cmu.edu> (raw)

Such code fragments never seem to be completely equivalent.  Your structure is
not equivalent for expanded names, e.g., PROC.LOOP_NAME.I, won't be possible
because you've introduced an extra level of declare block.

In addition, language commentary AI-00006 says that the subtype of the loop
parameter is determined by the discrete range of the loop.  "In particular, if
the discrete range is static, the loop parameter has a static subtype".  This
affects the legality of case statements:

	for J in 1..2 loop
	    case J is
		when 1 => ... ;
	    	when 2 => ...;
	    end case;

No other choices are allowed or required.

Also, your equivalence should emphasize that the loop parameter is defined by
a base type:

	type T is range 0..255;
	
	for I in T'BASE'FIRST..T'PRED(T'FIRST) loop
	    -- no exception and no positive values!

So, your equivalence should be:

    DECLARE
      <lb> : CONSTANT <Base-Type-Mark> := E1;
      <is> : <Base-Type-Mark> := <lb>;
      <ub> : CONSTANT <Base-Type-Mark> := E2;
    BEGIN
      IF <is> <= <ub>
	THEN
	  LOOP
	    DECLARE
	      I : CONSTANT <Base-Type-Mark> RANGE <lb> .. <ub> := <is>;
	    BEGIN
	      <body>
	    END;
	    EXIT WHEN <is> = <ub>;
	    <is>:= <Type-Mark>'SUCC(<is>);
	  END LOOP;
      END IF;
    END;

The initialization of I with <is> ensures that I cannot be used in a static
expression, since it is not a static constant.

Having had bad luck with trying to define such equivalences, it wouldn't
surprise me if there is something else wrong with the above equivalence (apart
from the expanded name problem).  Any such problem will almost certainly have
to do with interactions with other rules in the language, and not the semantic
behavior of the loop.

John B. Goodenough (Goodenough@sei.cmu.edu)
Software Engineering Institute
Pittsburgh, PA  15213
412-268-6391

             reply	other threads:[~1988-07-19 13:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-07-19 13:52 John.Goodenough [this message]
  -- strict thread matches above, loose matches on Subject: below --
1988-07-18 20:15 FOR Iteration Scheme Richard Pattis
1988-07-19 20:43 ` David E. Emery
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox