From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!AMSTEL.llnl.gov!WILSON From: WILSON@AMSTEL.llnl.gov (One Heppy Heppy 'Ket') Newsgroups: comp.lang.ada Subject: Iterate constructs Message-ID: Date: 10 Apr 90 22:56:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet List-Id: Erland Sommarskog considers the virtues of an out mode "Continue" parameter for generic iteration routines vs. using an exception to exit that routine. My preference would be to using the "Continue" parameter, even though it might not be used more than 10% of the time. There are several issues here. First, using the parameter makes it obvious just what functionality is provided by the routine, at the specification level. Second, it's important that the iterate routine know that a user exception may be raised, in case the iterate routine needs to clean up the data structure before exiting; if this mechanism is to be used, this cleanup needs to be performed in an internal "when others" exception handler, which can accidentally mask internal errors. Third, there is the philosophical problem of raising an exception in a non-exceptional case. Normally I leave this issue up to the individual programmers, but I don't like the idea of writing a general purpose package which requires that behavior of the package user. There are two other alternatives. First, the generic package itself could define the exception DONE, and require the user to raise that exception to get out early. This has the advantage that it is defined in the package specification, and that the package body can trap for that exception explicitely, and that the instantiated procedure does not need to exit itself with an exception. The other alternative is to define two iterate routines, ITERATE and ITERATE_ALL, where ITERATE takes a generic procedure with the "Continue" parameter. This has the disadvantage of cluttering up the specification with a second routine with little added value, but it avoids the exception issue altogether. My preference is for the single ITERATE with a "Continue" parameter. We use this construct in many of our packages, and I'd guess that we take advantage of the early exit around 1/2 the time. (One problem we have with this is that if the user forgets to provide a value of "TRUE" for this parameter, our compiler does not mention that we have an unassigned out mode parameter, and the iterate routine exits unpredictably.) --- Rick Wilson