[comp.lang.eiffel] eiffel loops

genly@bubble.multiflow.COM (Chris Hind Genly) (04/07/89)

Why isn't there a STEP clause for Eiffel loops?  The STEP clause would
be executed after the LOOP body and is intended to change the value of
the variant for the next iteration of the loop.  With this addition
the body of LOOP would no longer change the variant.

Clearly STEP is not needed in order to be able to write working loops,
but neither is FROM.  In the same way that FROM clearly documents the
part of the code used to start a loop, STEP would document the part of
a loop that changes the variant.

STEP along with FROM, UNTIL, VARIANT, and INVARIANT would allow reasoning
about the correctness of the loop without having to refer to the LOOP body.
This would provide a clear separation between the job of LOOPING and the
job performed by the body of the loop.  For instance the job of printing
all the members of a list could be thought of as

	FOR_ALL_MEMBERS_OF_THE_LIST
		list_member.print

The idea of looping through the members of a list is separate from the
operations performed on the members of a list.  I can reason about the
correctness of FOR_ALL_MEMBERS_OF_THE_LIST without knowing about
printing a member of the loop.  STEP would complete the separation of
the of variant from the loop body.

There are other features that could be added to support loops better
but most of these seem to go beyond the Eiffel approach of simplicity.
(Which, by the way, I like.  Eiffel has a clean feel.)  STEP seems to
be compatible with the Eiffel approach so I'll stop by asking if STEP
could be added to the language.