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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no 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-18 11:16:35 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny02.gnilink.net.POSTED!53ab2750!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: Subject: Re: ML-like alternatives to out parameters for functions 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 Message-ID: Date: Tue, 18 Mar 2003 19:16:34 GMT NNTP-Posting-Host: 141.157.180.124 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny02.gnilink.net 1048014994 141.157.180.124 (Tue, 18 Mar 2003 14:16:34 S) NNTP-Posting-Date: Tue, 18 Mar 2003 14:16:34 S Xref: archiver1.google.com comp.lang.ada:35474 Date: 2003-03-18T19:16:34+00:00 List-Id: "Mark Lorenzen" wrote in message news:m31y14bj83.fsf@valhal.vikingnet... > But again this relies on side-effects on it's parameters. I would go > for a solution like this: > > function Random (Gen : in Generator) return Random_Continuation > > where > > type Random_Continuation is > record > Gen : Generator; > Value : Uniformly_Distributed; > end record; There are two problems with this approach. One is that it assumes that Generator is not a limited type; currently Generator is limited. But even if we change the declaration of Generator, this version of Random places a heavy burden on the caller. In almost all cases, users of this function simply want to get the next random number and update the generator. With this version of Random, this can be accomplished only be doing something like this: declare Temp : constant Random_Continuation := Random( Gen ); begin Gen := Temp.Gen; Value := Temp.Value; end; Do you really want to require this for every call to Random? Another possible solution would be to implement Random as a procedure, i.e. procedure Random( Gen : in out Generator; Value : out Uniformly_Distributed ); This approach would probably the best approach given the current Ada 95 restrictions, since it specifies precisely how Random works: it updates the generator and returns a value. For ease of use, however, it would be hard to beat the function solution with the "in out" parameter (if it only were legal Ada!).