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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6b85f5fd782a1527 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: How to Use Abstract Data Types Date: 1998/05/06 Message-ID: <3550754C.2ECB539B@gsfc.nasa.gov>#1/1 X-Deja-AN: 350785420 Content-Transfer-Encoding: 7bit References: <6hm556$95u$1@nnrp1.dejanews.com> <354F5C4D.DFF8286E@gsfc.nasa.gov> Content-Type: text/plain; charset=us-ascii Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-05-06T00:00:00+00:00 List-Id: Matthew Heaney wrote: > In article <354F5C4D.DFF8286E@gsfc.nasa.gov>, Stephen Leake > wrote: > > (start of quote) > I like this technique, too, but one problem I have with it is it assumes > read-write access to the Library. Suppose I want to implement Find: > > function Find (Title : in String; Library : in My_Library) return Book'class > is > Iterator : Library_Iterator (Library'access); -- illegal > begin > ... > end Find; > > Since the Library parameter is "in", you cannot use it as the access > discriminant. > (end of quote) > > If you're using GNAT, then you can use the Unrestricted_Access attribute, ie > > Iter : Lib_Iter (Lib'Unrestricted_Access); > begin > ... > > This gives you the ability to make state changes behind the scenes (or, > here, supply an in param as an actual discriminant), even though the object > is publically read-only. (In Meyer's terminology, you change the > "concrete" state without changing the "abstract" state.) > > C++ programmers take this ability for granted, because you can "cast away > const." It's a bummer you can't do that portably in Ada 95. Oh, well. > Maybe some programmer will write another article in JOOP explaining that we > need to "extend the syntax" of Ada 95... > I've wondered if allowing "constant" in an access discriminant declaration would do the trick: type Read_Only_Library_Iterator (Library : access constant My_Library) is record ... This seems like a reasonable syntax extension. -- Stephe