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,50137bb64a119cfc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-24 11:11:57 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: "access constant" discriminant Date: 24 Feb 2003 11:11:57 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0302241111.3e816bb@posting.google.com> References: <_TO1a.14664$9y2.6601@nwrddc01.gnilink.net> <3CS1a.55972$2H6.1357@sccrnsc04> <3E4E9248.3E71D984@adaworks.com> <1ec946d1.0302201642.66eb93e5@posting.google.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1046113917 21756 127.0.0.1 (24 Feb 2003 19:11:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 24 Feb 2003 19:11:57 GMT Xref: archiver1.google.com comp.lang.ada:34529 Date: 2003-02-24T19:11:57+00:00 List-Id: "Randy Brukardt" wrote in message news:... > Matthew Heaney wrote in message > <1ec946d1.0302201642.66eb93e5@posting.google.com>... > > >Here we see the reason why we passed an access parameter: it's because > >we're returning an access value that designates one of our own > >components. > > > That reason being only that Ada doesn't support 'in out' parameters on > functions. If it did, > > fuction Persistence_View > (Object : in out T) return Persistence_Class_Access is > begin > return Object.Persistence_View'Access; > end; > > would work fine, and would be a lot easier to use as well. No -- this would be the wrong way to implement the multiple views idiom. You really do want to make explicit the fact that the object is being aliased. For example, in C++ I could do this: X x; Y y(x); and implement Y this way: class Y { X& x; public: Y(X& xx) : x(xx) {} //... private: Y(const Y&); Y& operator=(const Y&); }; but that would be entirely misleading, even if it's "easier" to declare a Y object. It's better to implement Y's ctor using an explicit pointer: class Y { X& x; public: Y(X* px) : x(*px) {} private: Y(const Y&); Y& operator=(const Y&); }; and then say: X x; Y y(&x); Which makes it identical to how you'd say it in Ada95. So this is not really an Ada issue. > But that's not going to happen, so we're stuck with terrible workarounds > like 'access' parameters. Access parameters have other uses besides getting around the lack of inout mode for function parameters. For example, operations that accept a user-defined type as an access parameter are primitive for the type, and hence are inherited in a derivation. And an access parameter means you don't have to say Op (O.all) everywhere. However, we are in agreement that not having inout mode for functions is a ridiculous restriction, since functions in Ada95 do modify their arguments (the language just doesn't let you *say* that you do).