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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-23 20:52:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? References: <568ede3c.0309160929.1d0d3d95@posting.google.com> <3F67AFB9.7040001@attbi.com> <3F6F0841.60607@attbi.com> <1064244399.683441@master.nyc.kbcfp.com> <3F70021A.2010305@attbi.com> <1064320198.65725@master.nyc.kbcfp.com> 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: Wed, 24 Sep 2003 03:52:43 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1064375563 65.110.133.134 (Tue, 23 Sep 2003 20:52:43 PDT) NNTP-Posting-Date: Tue, 23 Sep 2003 20:52:43 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:42842 Date: 2003-09-24T03:52:43+00:00 List-Id: Hyman Rosen writes: > Are the functions allowed to modify the state of the object? I assume > no, since functions only take IN parameters. Never assume. The answer is, "it depends." Functions can of course have access parameters: type T is record ... end record; function Modify (O : access T) return Whatever; This is a function that can modify its parameter O, because it's passed an access parameter which is basically the same as inout. If the type is limited, then you can use the trick discovered by that other Rosen: type T; type Rosen_Trick (O : access T) is limited null record; type T is limited record Jean_Pierre : Rosen_Trick (T'Access); ... end record; function Modify (O : in T) return Whatever is Modifiable : T renames O.Jean_Pierre.O.all; begin ... -- modify Modifiable as desired end; In fact the bounded linked-list containers in my AI-302 proposal are implemented using the Rosen Trick, precisely because I have in-params that need to change container state. If you have a non-limited type that is pass-by-reference, then you can use address-to-access conversions to get a variable view of the in-param and then modify it that way. You have to leave the type system very briefly so be careful. Functions in Ada are basically value-returning subprograms that can modify state just like procedures, but aren't allowed to say that they modify state. This is one thing Ada got wrong and C++ got right. Ideology should never trump reality.