[bitc-dev] Error in specification of DO
David-Sarah Hopwood
david.hopwood at industrial-designers.co.uk
Wed Jul 9 17:16:06 CDT 2008
Jonathan S. Shapiro wrote:
> I have just realized that the specification of DO is not what we wanted.
> I followed the Scheme specification of DO here. You will find on the web
> statements in various places that Scheme DO implements DO-UNTIL. Those
> statements are incorrect. What Scheme DO implements is in fact
> WHILE-NOT. That is: a Scheme DO loop may not perform any executions of
> the body at all.
>
> I tend to believe that there are good uses for all of the following
> constructs:
>
> WHILE perform body while test remains tr
> WHILE-NOT perform body while test remains false
> DO-UNTIL perform body until test becomes true, running at least
> once.
>
> Of the three, I believe that WHILE-NOT is the least commonly useful, and
> that it is trivially subsumed by WHILE.
C-family languages have DO..WHILE rather than DO..UNTIL, of course.
The (small) advantages of this are:
- familiarity to C, C++, Java and C# programmers,
- changing a loop between the WHILE and DO..WHILE forms does not
require inverting the condition.
I briefly looked at uses of 'do {...} while (condition)' in my C code,
and it did not seem like "negative" conditions were generally any more
common than "positive" ones (i.e. that the code would have been made
clearer by being able to invert the condition).
A minor advantage of DO..UNTIL is that the condition acts as an
assertion that is true after the loop (rather than false after the
loop, which might require a reader of the code to mentally invert it
in more cases). I would consider this to be less important than the
familiarity issue.
--
David-Sarah Hopwood
More information about the bitc-dev
mailing list