comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthewjheaney@earthlink.net>
Subject: Re: XML DOM Binding for Ada 95 - matter of style
Date: Thu, 07 Aug 2003 12:28:49 GMT
Date: 2003-08-07T12:28:49+00:00	[thread overview]
Message-ID: <5CrYa.421$Nf3.207@newsread4.news.pas.earthlink.net> (raw)
In-Reply-To: bgoboh$pae$1@a1-hrz.uni-duisburg.de


"Georg Bauhaus" <sb463ba@d2-hrz.uni-duisburg.de> wrote in message
news:bgoboh$pae$1@a1-hrz.uni-duisburg.de...
> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>
> You don't need to know about them during the design process,
> but you can construct "signature instances" like so:
>
> generic
>   type X is private;
>   function count(thing: X) return Natural;
>   procedure stretch(thing: in out X);
> ...
>
> and then instantiate "..." with whatever actuals seem fit.

This is exactly how the generic algorithms in Charles work.  Something like:

generic
   type Iterator_Type is private;
   with function Succ (I : Iterator_Type) return Iterator_Type is <>;
   with function Is_Less (L, R : Iterator_Type) return Boolean is <>;
  ...
function Generic_O (First, Back : Iterator_Type)
  return Iterator_Type;

There are only a few algorithms in there, because I'm still busy working on
the containers.


> This doesn't require that the provider of the units from which
> X, count, etc. are taken, has to know beforehand that his/her types,
> functions, or whatever will be used this way.

To a point.  But often, you design a type anticipating that that type will
the used as a generic actual.  For example, in Charles, all the iterator
types (indeed, all the containers) have an identical interface (meaning that
all the operation names are the same).  This allows you pass "default"
subprogram actuals, e.g.

function Op is new Generic_Op (Iterator_Type);
--This works because Succ and Is_Less are directly
--visible at the point of instantiation.


> Actually, you can pass operations of a tagged type as actuals.
> Can this be done with virtual member functions in C++?

Well, yes and no.  You can dispatch on the operation, which would be the
only point of doing it, e.g.

generic
   type T (<>) is abstract tagged limited private;
   with function Op (O : in T) is <>;
procedure Generic_Dispatch (O : in T'Class);

procedure Generic_Dispatch (O : in T'Class) is
begin
  Op (O);   --illegal
end;

To do generic dispatching, you have to use a trick, um, I mean "technique,"
which involves passing a class-wide operation instead:

generic
   type T (<>) is limited private;
   with procedure Op (O : in T) is <>;
procedure Generic_Dispatch (O : in T) is
begin
   Op (O);
end;

Now suppose we have a tagged type:

package P is
   type T is tagged limited null record;
   procedure Op (O : T); --primitive
end;

Somehow we'd like to pass an object of type T'Class as a parameter to the
instantion, and dispatch Op.  The way to do this is create a little wrapper
subprogram for Op:

procedure P.Call_Op (O : in T'Class) is
begin
   Op (O); --dispatches
end;

Now we have everything we need to instantiation generic op.  The solution to
the problem is to pass type T'Class as the generic actual type:

procedure Dispatch is
   new Generic_Dispatch (T => T'Class, Op => Call_Op);

Now when we do this:

procedure Op2 (O : T'Class) is
begin
   Dispatch (O);
end;

then the primitive operation Op will dispatch according to the tag of O.






  parent reply	other threads:[~2003-08-07 12:28 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-30 11:32 XML DOM Binding for Ada 95 - matter of style DENNY VRANDECIC
2003-07-30 12:33 ` Martin Dowie
2003-07-30 15:20   ` Denny Vrandecic
2003-07-30 16:33     ` Stephen Leake
2003-07-31 10:57       ` Marin David Condic
2003-07-31 11:27         ` Preben Randhol
2003-07-31 13:10           ` Matthew Heaney
2003-07-31 19:04             ` Simon Wright
2003-08-02 14:40               ` Matthew Heaney
2003-07-31 20:25             ` Randy Brukardt
2003-08-01 11:46           ` Marin David Condic
2003-08-02  3:40             ` Matthew Heaney
2003-08-02 12:08               ` Marin David Condic
2003-08-02 14:46                 ` Matthew Heaney
2003-08-02 21:25                   ` Ed Falis
2003-08-05 19:59                   ` Marin David Condic
2003-08-03 16:42                 ` Matthew Heaney
2003-08-04  8:04                   ` Dmitry A. Kazakov
2003-08-05  8:00                     ` Georg Bauhaus
2003-08-05 11:46                       ` Dmitry A. Kazakov
2003-08-05 13:34                         ` Georg Bauhaus
2003-08-06  9:03                           ` Dmitry A. Kazakov
2003-08-06 18:15                             ` signature like constructions (was: Re: XML DOM Binding for Ada 95 - matter of style) Georg Bauhaus
2003-08-07 10:12                               ` Dmitry A. Kazakov
2003-08-07 16:22                                 ` signature like constructions Georg Bauhaus
2003-08-08  8:31                                   ` Dmitry A. Kazakov
2003-08-08 10:12                                     ` Robert I. Eachus
2003-08-08 13:29                                       ` Dmitry A. Kazakov
2003-08-08 19:37                                         ` Robert I. Eachus
2003-08-09  0:58                                           ` Alexander Kopilovitch
2003-08-09  7:39                                             ` Robert I. Eachus
2003-08-10  1:30                                               ` Alexander Kopilovitch
2003-08-10  4:11                                                 ` Robert I. Eachus
2003-08-11 10:25                                           ` Dmitry A. Kazakov
2003-08-08 23:44                                         ` Alexander Kopilovitch
2003-08-11  9:54                                           ` Dmitry A. Kazakov
2003-08-11 14:59                                             ` Alexander Kopilovitch
2003-08-12  9:54                                               ` Dmitry A. Kazakov
2003-08-13 22:28                                                 ` Alexander Kopilovitch
2003-08-09  8:32                                       ` Simon Wright
2003-08-09 15:32                                         ` Robert I. Eachus
2003-08-07 12:52                             ` XML DOM Binding for Ada 95 - matter of style Matthew Heaney
2003-08-07 15:03                               ` Dmitry A. Kazakov
2003-08-07 12:28                           ` Matthew Heaney [this message]
2003-08-05 20:05                   ` Marin David Condic
2003-07-30 16:34     ` Martin Dowie
2003-07-30 17:54 ` tmoran
replies disabled

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