comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Booch: missing r/w access through iterators
Date: 8 Nov 2002 12:49:10 -0800
Date: 2002-11-08T20:49:10+00:00	[thread overview]
Message-ID: <1ec946d1.0211081249.68cf4d7b@posting.google.com> (raw)
In-Reply-To: x7vn0ol148m.fsf@smaug.pushface.org

Simon Wright <simon@pushface.org> wrote in message news:<x7vn0ol148m.fsf@smaug.pushface.org>...
> porton@ex-code.com (Victor Porton) writes:
> 
> I can see why you might want it, and at the moment I can't remember
> why it's not there. Perhaps something to do with the problem of
> creating the access value? (it would force the item in the Container
> to be aliased, thus constraining it .. I know this actually happens in
> the BCs but I was very unhappy with the necessary kluge).

Simon is correct that the elements in the container will have to be
aliased.  If you have an element type that is an definite,
unconstrained record, like this:

   type DT is (A, B, C);

   type RT (D : DT := DT'First) is record ... end record;

then the simplest thing to do is wrap this in another record:

   type Element_Type is
      record
         R : RT;
      end record;

and then instantiate the component with the wrapper type:

   package Set_Types is 
     new Charles.Sets.Unbounded (Element_Type, ...);

Now you can do this to get at the element:

   type Element_Access is 
     access all Element_Type;

   function To_Access is
     new Generic_Element (Element_Access);

   declare
      E : Element_Type renames To_Access (Iterator).all;
   begin
      <now modify E.R>
   end;

The Charles library is available at my home page:

http://home.earthlink.net/~matthewjheaney/charles/index.html

The reason this restriction exists is because of access subtypes.  For
example, given our discriminated record type above, we can do this:

   type R_Access is access RT;

   subtype RA_Access is R_Access (A);

The issue is that if you have this:

   RA : RA_Access := new RT'(D => A, ...);

then you always have a guarantee that the discriminated record object
designated by access object RA always has a discriminant with the
value DT'(A).

You're not allowed to change the discriminant of an aliased
unconstrained discriminated record, because that would break the
guarantee.

This is arguably a flaw in the language.  The type model is consistent
in that you it supports subtypes of types, but extending that model to
include access types too was probably too much of a good thing.

The problem is that you need an aliased unconstrained discriminated
record a lot more often than you need an access subtype.  Hence the
problem to which Simon was refering.



  reply	other threads:[~2002-11-08 20:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-06 14:18 Booch: missing r/w access through iterators Victor Porton
2002-11-06 16:42 ` Simon Wright
2002-11-07  4:21 ` Victor Porton
2002-11-07 21:04   ` Simon Wright
2002-11-08 20:49     ` Matthew Heaney [this message]
2002-11-08 20:37   ` Matthew Heaney
2002-11-08  5:21 ` Victor Porton
2002-11-08 20:53   ` Matthew Heaney
2002-11-08 20:33 ` Matthew Heaney
replies disabled

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