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,4180a73b05d119c7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-17 20:19:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.airnews.net!cabal12.airnews.net!usenet From: "John R. Strohm" Newsgroups: comp.lang.ada Subject: Re: ML-like alternatives to out parameters for functions Date: Mon, 17 Mar 2003 21:54:47 -0600 Organization: Airnews.net! at Internet America Message-ID: <6E9629ED3B97E719.37A71B467CC92E55.97C7FAA82EDFF034@lp.airnews.net> X-Orig-Message-ID: References: Abuse-Reports-To: abuse at airmail.net to report improper postings NNTP-Proxy-Relay: library2.airnews.net NNTP-Posting-Time: Mon Mar 17 22:17:26 2003 NNTP-Posting-Host: ![n="1k-X$k])]M (Encoded at Airnews!) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Xref: archiver1.google.com comp.lang.ada:35434 Date: 2003-03-17T21:54:47-06:00 List-Id: "Mark Lorenzen" wrote in message news:m365qhh8ju.fsf@valhal.vikingnet... > Stephen Leake writes: > > > Mark Lorenzen 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?)