comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.leake@gsfc.nasa.gov>
Subject: Re: How to Use Abstract Data Types
Date: 1998/05/06
Date: 1998-05-06T00:00:00+00:00	[thread overview]
Message-ID: <3550754C.2ECB539B@gsfc.nasa.gov> (raw)
In-Reply-To: matthew_heaney-ya023680000505981941000001@news.ni.net


Matthew Heaney wrote:

> In article <354F5C4D.DFF8286E@gsfc.nasa.gov>, Stephen Leake
> <stephen.leake@gsfc.nasa.gov> 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






  reply	other threads:[~1998-05-06  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-22  0:00 How to Use Abstract Data Types adam
1998-04-23  0:00 ` Jacob Sparre Andersen
1998-04-30  0:00 ` Robert I. Eachus
     [not found]   ` <matthew_heaney-ya023680003004981709380001@news.ni.net>
1998-05-05  0:00     ` Stephen Leake
1998-05-05  0:00       ` Matthew Heaney
1998-05-06  0:00         ` Stephen Leake [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-04-30  0:00 adam
1998-05-06  0:00 ` Robert I. Eachus
1998-05-04  0:00 adam
1998-05-06  0:00 ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox