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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fa18fb47ddd229a7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-10 15:12:28 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Proposed change to BC iterator parameters Date: 10 Dec 2003 18:12:26 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: pip1-5.std.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1071097946 10655 192.74.137.185 (10 Dec 2003 23:12:26 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 10 Dec 2003 23:12:26 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:3343 Date: 2003-12-10T18:12:26-05:00 List-Id: "amado.alves" writes: > <<... > generic > type Param_Type is private; > with procedure Apply (Elem : in Item; > Param : in Param_Type; > OK : out Boolean); > procedure Visit_With_In_Param (Using : in out Iterator'Class; > Param : in Param_Type); > >> > > I've never found a situation where the following much simpler signature wouldn't suffice: > > generic > with procedure Apply (Elem : in Item); > procedure Visit_With_In_Param (Using : in out Iterator'Class); > > with premature termination of the iteration done by raising inside > Apply an exception which Visit_With_In_Param propagates by > definition. Yeah, that works. It's not very efficient (in most implementations). If you want to stop the loop as soon as you found the thing you're looking for, it's quite likely that the exception-handling overhead is more than the cost of letting the loop keep going to the end. Ada really doesn't have very good support for iterators. This is one example. The iterator abstraction should not have to worry about premature exits -- the loop code should just jump out of the loop. A goto statement would be better than an exception here, because you're going to a specific place (as opposed to raising an exception that could be handled who-knows-where). You can do that in Pascal, but Ada doesn't allow gotos out of procedures (for good reason -- consider a procedure called by a nested task). (Goto haters should consider that exceptions are just like gotos, except you don't know statically where they're going to -- i.e., exceptions are *worse* than gotos, from a structured programming point of view.) I don't understand the point of Param_Type and Param above. If you want to pass extra information to Apply, nest the instantiation in a place where it can see that data. - Bob