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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bd40601768eaf8fd X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Array of Variant Records Question... Date: 1999/09/10 Message-ID: <37d9a3b7@news1.prserv.net>#1/1 X-Deja-AN: 523599456 Content-transfer-encoding: 7bit References: <7r5vh3$imu1@svlss.lmms.lmco.com> <37d6a45c@news1.prserv.net> <37d6ccb6@news1.prserv.net> <7r77i8$i08$1@nnrp1.deja.com> <37d7c116@news1.prserv.net> <7r8t21$ov5$1@nnrp1.deja.com> <37d822a1@news1.prserv.net> <7r9r4u$fsc$1@nnrp1.deja.com> <37D96965.81045235@rational.com> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 11 Sep 1999 00:35:03 GMT, 32.101.8.205 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-09-10T00:00:00+00:00 List-Id: In article <37D96965.81045235@rational.com> , Mark Lundquist wrote: >> That seems just *too* kludgy to me, and very implemention >> dependent, wouldn't it be better to just introduce in out >> and out parameters for functions (but we know that one won't >> fly ...) >> > > Why would that be necessary, since functions already can have access > parameters? OK, the actual must denote an aliased view... It's like I said in another post: sometimes you have an operation that is publicly in-mode, but privately in-out. The function Random is declared this way: function Random (G : in Generator) return Result_Subtype; >From an abstract point of view, Generator provides a stream of random numbers, and function Random simply returns successive values from this stream. The stream is just out there, in the ether, and no modification of this stream is required. >From an implementation point of view, however, invoking the function Random changes the state of the Generator. That's why you need a way to "cast away const," to be able to change state of an object whose parameter mode is in. The AARM suggests a way to implement this type, by using a level of indirection. However, this means allocating the internal state on the heap, and implementing Generator by privately deriving from Limited_Controlled (to reclaim the memory). This is an awfully heavy solution, compared to the alternative. Now you're right, you could declare Random this way: function Random (G : access Generator) return Result_Subtype; and everything would be hunky-dory. But how would you feel about actually using that function: declare G : aliased Generator; begin ... Random (G'Access) ... end; Compare that to: declare G : Generator; begin ... Random (G) ... end;