comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: ML-like alternatives to out parameters for functions
Date: Tue, 01 Apr 2003 03:39:25 GMT
Date: 2003-04-01T03:39:25+00:00	[thread overview]
Message-ID: <3E890A20.8080108@attbi.com> (raw)
In-Reply-To: mgKda.72158$gi1.33350@nwrdny02.gnilink.net

Frank J. Lhota wrote:

> 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!).

Let's not revisit this again.  During the Ada 9X development process, 
the arguments on both sides were explained, and a formal WG9 vote taken 
(by countries--this is ISO).  Allowing function parameters to have an in 
out mode was defeated.

Note that this does not mean you cannot write functions in Ada that 
alter their parameters.

    function Random(Gen: in Generator) return Uniformly_Distributed is
      Local_Gen: Generator;
      for Local_Gen'Address use Gen'Address;
    begin...

is perfectly legal Ada.  Note that in this particular case, since 
Generator is a limited type, it is only legal inside the body of the 
package that defines Generator (Presumbably Ada.Numerics.Float_Random, 
but you can write your own random number generators.  I do. ;-)

And that should make the reason why things have stayed the way they are 
perfectly clear.  There is a workaround for the cases where it is 
appropriate to work around the restriction, and the workaround is 
limited in a useful way.  You don't want users poking around inside the 
Generator object, and such poking around--by say passing the Generator 
object to a unit written in C--is flagged with warnings all around.






  reply	other threads:[~2003-04-01  3:39 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
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 [this message]
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