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!mailrus!uunet!ncrlnk!ncrwic!wsuiar!tdhammer From: tdhammer@wsuiar.uucp Newsgroups: comp.lang.ada Subject: Re: On quitting an iterator prematurely Message-ID: <120.26224a7e@wsuiar.uucp> Date: 11 Apr 90 02:05:01 GMT References: <9004041704.AA17624@ajpo.sei.cmu.edu> <1151@enea.se> Organization: Wichita State Univ., Wichita KS List-Id: In article <1151@enea.se>, sommar@enea.se (Erland Sommarskog) writes: [stuff from Cohen deleted] > > Some years ago I wrote a binary tree package with a similar concept. > When I was to use the package I discovered one thing I had missed. > There was no way to interrupt the iteration. One way is of course > to rewrite the package so that Process_one_element should take a > second parameter > Continue : OUT boolean; > The problem with this is that if the user in 90% of the time wants to > iterate through the entire set, this second parameter just clutters > up his code, and he may even forget to initiate it with interesting > results, unless the compiler catches the error. [more stuff deleted - code example] > Now, I wouldn't say that this is the use of exception as intended, > but rather a confirmation those who claim that says that exception is > a structured GOTO. Yet, if this is the rare case, this solution seem > to be preferable to a second, rarely-used continue parameter. > > What is the general opinion on this? Any better ideas? > -- > Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se My first reaction was that it was not the intended use of the exception, and then saw that the author admits it. I would go on to disagree with the argument of using the exception as a structured goto. An exception is exactly that, something that is not expected to occur and if it does is probably an error. My initial implementation thought would be to write a boolean function with any side effects of processing one element and returning the value for Continue. This perhaps comes from my C coding experiences and probably is not good practice. Perhaps this is an argument for an extension to the optional parameters to include out parameters that may or may not appear in the procedure call? That would be an interesting implementation. Tim .D. ------------------------------------------------------------------------------- Tim .D. Hammer BITNET: TDHAMMER@TWSUVAX Teaching/Research Assistant UUCP: uunet!ncrlnk!ncrwic!wsucsa!hammer Computer Science Dept. INTERNET: tdhammer@wsuiar.wsu.ukans.edu Wichita State University TalkNET: (316)689-3156 Wichita, Ks. 67208-1595 package DISCLAIMER is type VIEWS is NO_ONE_ELSES ; subtype OPINIONS is bigoted VIEWS ; end package DISCLAIMER ; ------------------------------------------------------------------------------- "A little learning is a dangerous thing." Alexander Pope