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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e528d54e6cc3c10d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!stamper.news.atl.earthlink.net!newsread3.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: why only in-parameters in functions References: From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 30 Sep 2004 01:55:08 GMT NNTP-Posting-Host: 64.185.133.124 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.atl.earthlink.net 1096509308 64.185.133.124 (Wed, 29 Sep 2004 18:55:08 PDT) NNTP-Posting-Date: Wed, 29 Sep 2004 18:55:08 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:4425 Date: 2004-09-30T01:55:08+00:00 List-Id: "Alexander E. Kopilovich" 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.