comp.lang.ada
 help / color / mirror / Atom feed
From: "John R. Strohm" <strohm@airmail.net>
Subject: Re: ML-like alternatives to out parameters for functions
Date: Mon, 17 Mar 2003 21:54:47 -0600
Date: 2003-03-17T21:54:47-06:00	[thread overview]
Message-ID: <6E9629ED3B97E719.37A71B467CC92E55.97C7FAA82EDFF034@lp.airnews.net> (raw)
In-Reply-To: m365qhh8ju.fsf@valhal.vikingnet

"Mark Lorenzen" <mark.lorenzen@ofir.dk> wrote in message
news:m365qhh8ju.fsf@valhal.vikingnet...
> Stephen Leake <Stephen.A.Leake@nasa.gov> writes:
>
> > Mark Lorenzen <mark.lorenzen@ofir.dk> writes:
> >
> > > An out parameter can be used when the validity of the result of
> > > evaluating a function is not always well-defined. For example:
> > >
> > > function Calculate (Argument : in AT; Result_Valid : out Boolean)
return RT;
> >
> > The prefered Ada solution for this particular case is to raise an
> > exception for errors, not return a status variable (or discriminant).
>
> It sure is. But if the problem being solved does not necessarily have
> a solution (and we can't determine if a solution exists before trying
> to solve it), then we would like to have a qualifier stating if a
> solution could be found or not. The C-way of doing this is typically
> to supply the address of a validity flag, that the function can set
> before returning a possible solution.

Well, it really depends on what it means to the rest of the application that
the problem being solved does not necessarily have a solution.

In my personal opinion, raising an exception is still the right thing to do,
in that it forces the caller to recognize that the solution is invalid and
deal with it.  The standard C library routines are notorious for returning
all kinds of status that says the main answer is invalid, and C programmers
are notorious for ignoring those return flags.  (When was the last time you
checked the return status on a printf(), for example?)





  reply	other threads:[~2003-03-18  3:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-17 22:17 ML-like alternatives to out parameters for functions Mark Lorenzen
2003-03-17 21:47 ` Stephen Leake
2003-03-17 23:34   ` Mark Lorenzen
2003-03-18  3:54     ` John R. Strohm [this message]
2003-03-18  8:59     ` Preben Randhol
2003-03-18 21:09     ` tmoran
2003-03-18 17:04   ` Frank J. Lhota
2003-03-18 18:52     ` Mark Lorenzen
2003-03-18 19:16       ` Frank J. Lhota
2003-04-01  3:39         ` Robert I. Eachus
2003-04-01 14:51           ` Frank J. Lhota
2003-03-18  8:37 ` Dmitry A. Kazakov
2003-03-18  9:07 ` Preben Randhol
2003-03-19  7:31 ` Mark Biggar
  -- strict thread matches above, loose matches on Subject: below --
2003-04-02  0:23 Alexandre E. Kopilovitch
replies disabled

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