From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: why only in-parameters in functions
Date: Thu, 30 Sep 2004 01:55:08 GMT
Date: 2004-09-30T01:55:08+00:00 [thread overview]
Message-ID: <u7jqcs8vp.fsf@earthlink.net> (raw)
In-Reply-To: mailman.131.1096477841.390.comp.lang.ada@ada-france.org
"Alexander E. Kopilovich" <aek@VB1162.spb.edu> writes:
> In practice, where you really need in-parameters for a function you
> may either use a procedure that returns value (if you use GNAT
> compiler) or you may use the construct, presented here in c.l.a by
> Robert I. Eachus (see his message in comp.lang.ada from 2003-07-15
> with Subject: Re: What evil would happen?)
>
> ----------------------------------------------------------------------------
>
> function Random(Gen: in Generator) return ...
> Local: Generator;
> for Local'Address use Gen'Address;
> begin
> ...
> end Random;
>
> ----------------------------------------------------------------------------
Actually, if the type is limited, then you can use the Rosen Trick,
which is somewhat cleaner:
private
type Handle (G : access Generator) is
limited null record;
type Generator is limited record
H : Handle (Generator'Access);
... -- rest of state
end record;
end;
function Random (G : Generator) return ...
GG : Generator renames G.H.G.all;
begin
... -- modify GG as desired
end Radom;
The Rosen Trick was discovered in the fall of 1999. See CLA archives
around that time for more info.
prev parent reply other threads:[~2004-09-30 1:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-29 15:18 why only in-parameters in functions Rick Santa-Cruz
2004-09-29 15:30 ` stephane richard
2004-09-29 16:55 ` Alexander E. Kopilovich
2004-09-29 21:10 ` Randy Brukardt
2004-09-29 23:37 ` Björn Persson
2004-09-29 23:46 ` Rick Santa-Cruz
2004-09-29 21:12 ` Florian Weimer
2004-09-30 7:41 ` Dmitry A. Kazakov
2004-09-29 22:42 ` Wojtek Narczynski
2004-09-30 1:55 ` Matthew Heaney [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox