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,FREEMAIL_FROM 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 14:27:52 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!skynet.be!skynet.be!newsfeed1.uni2.dk!news.get2net.dk.POSTED!53ab2750!not-for-mail Sender: malo@valhal.vikingnet Newsgroups: comp.lang.ada Subject: Re: ML-like alternatives to out parameters for functions References: From: Mark Lorenzen Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: 18 Mar 2003 00:34:13 +0100 NNTP-Posting-Host: 62.84.221.216 X-Complaints-To: abuse@colt-telecom.dk X-Trace: news.get2net.dk 1047940071 62.84.221.216 (Mon, 17 Mar 2003 23:27:51 CET) NNTP-Posting-Date: Mon, 17 Mar 2003 23:27:51 CET Organization: Colt Telecom Kunde Xref: archiver1.google.com comp.lang.ada:35428 Date: 2003-03-18T00:34:13+01:00 List-Id: 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. Am I wrong to assume that the Ada-way is definitely to use the discriminated return type, even in the case that Ada may get out parameters for functions? The reason for my question is that I have not seen this approach in Ada before. The solutions I have seen used a procedure like: procedure Proc (Arg : in AT; Result : out RT; Validity : out Boolean); which is just a variant of the C hack and definately not beautiful. - Mark Lorenzen