comp.lang.ada
 help / color / mirror / Atom feed
From: tdhammer@wsuiar.uucp
Subject: Re: On quitting an iterator prematurely
Date: 11 Apr 90 02:05:01 GMT	[thread overview]
Message-ID: <120.26224a7e@wsuiar.uucp> (raw)
In-Reply-To: 1151@enea.se

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

  parent reply	other threads:[~1990-04-11  2:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9004041704.AA17624@ajpo.sei.cmu.edu>
1990-04-08 12:07 ` On quitting an iterator prematurely Erland Sommarskog
1990-04-10 18:26   ` Sylvain Louboutin, University College Dublin, Ireland
1990-04-10 18:38   ` On quitting an iterator prematurely, erratum Sylvain Louboutin, University College Dublin, Ireland
1990-04-11  2:05   ` tdhammer [this message]
1990-04-13 22:04     ` On quitting an iterator prematurely David Kassover
1990-04-13 22:50       ` Mike Feldman
1990-04-11 11:38 Mats Weber
     [not found] <9004262133.AA06607@hac2arpa.hac.com>
     [not found] ` <7050@fy.sei.cmu.edu>
1990-05-01 16:09   ` On quitting an Iterator Prematurely Mike Feldman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox