comp.lang.ada
 help / color / mirror / Atom feed
From: "Mark Lundquist" <mlundquist2@attbi.com>
Subject: Re: Ada 200X Assertions
Date: Wed, 05 Dec 2001 22:00:13 GMT
Date: 2001-12-05T22:00:13+00:00	[thread overview]
Message-ID: <NNwP7.2247$dp6.159279@rwcrnsc54> (raw)
In-Reply-To: slrna0stp1.pjb.lutz@belenus.iks-jena.de


"Lutz Donnerhacke" <lutz@iks-jena.de> wrote in message
news:slrna0stp1.pjb.lutz@belenus.iks-jena.de...
> * Matthew Heaney wrote:
> >"Lutz Donnerhacke" <lutz@iks-jena.de> wrote in message
> >> Typical example 2: A head node of a linked list contains a next pointer
> >>     which should be handled exactly as the next pointer of the real
> >>     list nodes, but no payload at all.
> >
> >In the code below, I do this by making the List_Type a private derivation
of
> >a Node_Type. Which means a List_Type, containing only the head pointer,
can
> >be used exactly like Node_Type.
>
> >   type Node_Type is abstract tagged private;
> >   type List_Type is new Node_Type with private;
>
> That's not a generic mixin.
>
> My job is:
>   task type Bla is ...;
>   type Blas is array (Positive range <>) of Bla;
>   type Foo (len : Natural) is abstract record
>     t : Bla (Positive'First .. len);
>   end record;
>   procedure Process (a : Foo) is abstract;
>
>   package Bla_List is new List (Bla);
>   package Bla_List2 is new List (Bla);

Well, what you have there is not really a mixin, either.  That's just a
"plain old" generic list :-) (POGL).

The mixin idiom takes a generic formal tagged type, and exports an extension
of that type with additional properties/behaviors.

The POGL gives you an "externally-linked"/"containing"/"value-oriented"
list, where the collection owns the items.  The mixin gives you an
"internally-linked"/"by reference"/"object-oriented" list, where the client
owns the items.

Now... I'll bet you can take the example I wrote, or the one Matt wrote, and
figure out how to make either a generic mixin, or a plain old generic list,
with a header using the access discriminant technique.

Your example is of a list of tasks.  Since these are limited, you have two
ways to go:

1) Use a POGL (as shown in your example).  That POGL will have to have the
formal item type as limited; such a POGL does not do any assignments to the
items, even though it owns and creates them.  Instead, it returns pointers
to the items.

2) Use a mixin on a tagged container type, like this:

    type Bla_Container is tagged record
        Contents : Bla;
    end record;

    package Bla_Lists is new Lists_Mixin (Base => Bla);
    subtype Listable_Bla is Bla_Lists.Item_Type;                -- whatever


Best,
Mark






  reply	other threads:[~2001-12-05 22:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-04  3:53 Ada 200X Assertions Richard Riehle
2001-12-04  8:54 ` Lutz Donnerhacke
2001-12-04 17:09   ` Robert Dewar
2001-12-05 14:34     ` Lutz Donnerhacke
2001-12-04 18:43   ` Matthew Heaney
2001-12-05 15:16     ` Lutz Donnerhacke
2001-12-05 18:40       ` Matthew Heaney
2001-12-05 19:25         ` Matthew Heaney
2001-12-05 19:36         ` Lutz Donnerhacke
2001-12-05 22:00           ` Mark Lundquist [this message]
2001-12-05 22:49             ` Matthew Heaney
2001-12-06  5:04               ` Mixins (was Re: Ada 200X Assertions) Mark Lundquist
2001-12-05 19:57       ` Access discriminants " Mark Lundquist
2001-12-05 21:30       ` Ada 200X Assertions Matthew Heaney
2001-12-05 21:32         ` Lutz Donnerhacke
2001-12-17  6:43       ` David Thompson
2001-12-17  8:55         ` Lutz Donnerhacke
2001-12-04 19:10 ` Randy Brukardt
2001-12-04 21:21   ` Ehud Lamm
2001-12-06  3:55     ` Richard Riehle
2001-12-06  9:41       ` Rod Chapman
2001-12-07 22:51     ` Mark Lundquist
2001-12-05  9:43 ` Volkert
replies disabled

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