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-20 16:42:33 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: 20 Feb 2003 16:42:33 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0302201642.66eb93e5@posting.google.com> References: <_TO1a.14664$9y2.6601@nwrddc01.gnilink.net> <3CS1a.55972$2H6.1357@sccrnsc04> <3E4E9248.3E71D984@adaworks.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 1045788153 20740 127.0.0.1 (21 Feb 2003 00:42:33 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 21 Feb 2003 00:42:33 GMT Xref: archiver1.google.com comp.lang.ada:34320 Date: 2003-02-21T00:42:33+00:00 List-Id: Stephen Leake wrote in message news:... > > Because the body needs to call other functions that take access types > (that may beg the question, but it's the best I can do :). Access parameters carry accessibility information around, to check that an object in an outer scope doesn't refer to another object in an inner scope. These accessibility checks can be turned off using the 'Unchecked_Access attribute, or by using a pragma to suppress Access_Check. One example of the use of access parameters is the "multiple views" idiom in Ada95, to effect the equivalent of multiple inheritance in other languages. For example, given a mechanism to store objects that are "persistent": procedure Write (Persistence : access Persistence_Type'Class); then we can save any object that supports this view, like this: Some_Object : aliased T; ... Write (Persistence_View (Some_Object'Access)); The selector function would be written as: function Persistence_View (Object : access T) return Persistence_Class_Access; In the canonical model, type T would have an aliased component whose type derives from Root_Persistence_Type, and the selector function is implemented simply as: fuction Persistence_View (Object : access T) return Persistence_Class_Access is begin return Object.Persistence_View'Access; end; 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. The view component would be implemented like this: type Persistence_Type is new Root_Persistence_Type (Object : access T) with null record; type T is limited record Persistence_View : aliased Persistence_Type (T'Access); ... end record; Presumably the Root_Persistence_Type has primitive operations for writing an object into a stream, e.g. procedure Write (Persistence : access Root_Persistence_Type; Stream : in out Root_Stream_Type'Class) is abstract; The Persisence_Type about would override the Write operation, to write a T object into the stream. It has visibility to the T object via its access discriminant. Access discriminants are very powerful. No serious Ada95 program can be written without them.