comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Converting access values
Date: 07 Jan 2005 16:23:54 -0500
Date: 2005-01-07T16:23:54-05:00	[thread overview]
Message-ID: <wcc3bxdorv9.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: gemini.i9yrab00bd9ue02as.nick.roberts@acm.org

Nick Roberts <nick.roberts@acm.org> writes:

> Mark Lorenzen <mark.lorenzen@ofir.dk> wrote:
> 
> > As I said in another posting, I am going for a design like this:
> > 
> > type Buffer_Slice is
> >    record
> >      Data  : Buffer_Ptr;
> >      First : Ada.Streams.Stream_element_Offset;
> >      Last  : Ada.Streams.Stream_element_Offset;
> >    end record;
> > ...
> > It solves the problem, but exposes a bit more information to the clients
> > than necessary. It is very easy for a client to address a slice outside
> > the bounds:
> > ...

To avoid that exposure, you can make the Buffer_Slice type private,
and provide the appropriate operations as subprograms.
The Buffer_Slices package can easily enforce the desired bounds checking.
Unfortunately, you then lose all the nice notations for dealing
with arrays -- you have to say "Set_Nth_Element(X, I, Blah)"
instead of "X(I) := Blah", or whatever.

> Since you put it that way, I see your point. I suppose it is an area where
> Ada fails to provide a level of abstraction that perhaps it should. It's
> almost as if we want a new kind of access type, the 'slice access' type,
> that can point to a slice of an array, e.g.:
> 
>    type Buffer_Slice is access range Stream_Element_Array;
> 
> objects of which, when dereferenced, can be used anywhere a
> Stream_Element_Array object can, and have the same attributes (First and
> Last and so on).

I don't agree with that approach.  The underlying problem here is that
private types cannot be made to mimic the predefined syntax.  I can
think of dozens of abstractions that are like arrays, where one would
like to use array-like syntax.  The Buffer_Slice thing that Mark
Lorenzen wants is just one example.  Sure, you could add that to the
language directly, but then you haven't solved the general problem.
The "right" solution, in my opinion, is to extend the "user-defined
operators" idea to allow user-defined array-indexing, literals,
aggregates, &c.

A similar issue: Ada does not support arbitrary-range integers.
Of course you can define a package to do it.  And you can define "+",
"*", &c to do the right thing.  But then you lose constrained subtypes,
case statements, integer literals, &c., all of which work fine on the
*predefined* integers.

- Bob



  reply	other threads:[~2005-01-07 21:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-05 22:31 Converting access values Mark Lorenzen
2005-01-05 23:32 ` Stephen Leake
2005-01-05 23:51   ` Mark Lorenzen
2005-01-06  0:18 ` Jeffrey Carter
2005-01-06  0:28   ` Mark Lorenzen
2005-01-07 16:55     ` Nick Roberts
2005-01-07 19:49       ` Mark Lorenzen
2005-01-07 20:23         ` Nick Roberts
2005-01-07 21:23           ` Robert A Duff [this message]
2005-01-11 17:02             ` Upkeep
2005-01-11 21:37               ` Robert A Duff
2005-01-12  4:56                 ` Alexander E. Kopilovich
2005-01-12 10:48                 ` Dmitry A. Kazakov
2005-01-07 21:17         ` Randy Brukardt
2005-01-07 22:15           ` Robert A Duff
2005-01-06 10:52 ` Dmitry A. Kazakov
2005-01-06 11:02 ` Duncan Sands
2005-01-06 12:17   ` Martin Dowie
2005-01-06 19:30   ` Mark Lorenzen
2005-01-06 20:40     ` Randy Brukardt
replies disabled

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