comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Array of Variant Records Question...
Date: 1999/09/13
Date: 1999-09-13T00:00:00+00:00	[thread overview]
Message-ID: <37dcf193@news1.prserv.net> (raw)
In-Reply-To: Pine.BSF.4.10.9909091910250.12989-100000@shell5.ba.best.com

In article <Pine.BSF.4.10.9909091910250.12989-100000@shell5.ba.best.com> ,
Brian Rogoff <bpr@shell5.ba.best.com>  wrote:

> Matt, can you give examples where you find that explicit conversions are
> painful, or damage readability?

Consider the Interpreter pattern.  An And_Exp is a Bool_Exp object with two
components, a left exp and a right exp.

The spec looks like this:


package Bool_Exps.And_Exps is

   type And_Exp is new Bool_Exp with private;

   function New_And
     (L, R : access Bool_Exp'Class)
      return Bool_Exp_Access;

    ...

private

   type And_Exp is
     new Bool_Exp with record
        L, R : Bool_Exp_Access;
     end record;

end Bool_Exps.And_Exps;


As you can see above, the constructor for the type accepts two access
parameters, and returns a pointer to the class-wide root type, which is
defined as

  type Bool_Exp_Access is access all Bool_Exp'Class;


Here's the implementation of the constructor:

   function New_And
     (L, R : access Bool_Exp'Class)
      return Bool_Exp_Access is

      use And_Exp_Storage;

      Exp : constant Exp_Access := New_Exp;
      -- type Exp_Access is access all And_Exp;
   begin
      Exp.L := Bool_Exp_Access (L);    -- (1)
      Exp.R := Bool_Exp_Access (R);    -- (2)

      return Bool_Exp_Access (Exp);    -- (3)
   end New_And;


Observe the following:

(1) L is an access parameter.  I have to manually convert

  L : access Bool_Exp'Class

to an access value of type

  type Bool_Exp_Access is access all Bool_Exp'Class;

What's the point?


(2) Same for R as for L in (1).

(3) Exp is an access object designating an And_Exp value.  I have to
manually convert an access value from

  type Exp_Access is access all And_Exp;

to an access value of

  type Bool_Exp_Access is access all Bool_Exp'Class;

But what's the point?  An And_Exp value is in And_Exp, but it's also in
Bool_Exp'Class.

The issue is that a tagged object kinda sorta has potentially many types:
it's own specific type, and the class-wide type of each of its ancestors.

I would prefer that all these manually conversions be done implicitly, so I
could just write:

   function New_And
     (L, R : access Bool_Exp'Class)
      return Bool_Exp_Access is

      use And_Exp_Storage;

      Exp : constant Exp_Access := New_Exp;
   begin
      Exp.L := L;
      Exp.R := R;

      return Exp;
   end New_And;


It's not a show-stopper though...





  reply	other threads:[~1999-09-13  0:00 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-08  0:00 Array of Variant Records Question Bruce Detter
1999-09-08  0:00 ` Martin C. Carlisle
1999-09-08  0:00 ` Ted Dennison
1999-09-08  0:00 ` Thank you Bruce Detter
1999-09-08  0:00   ` Martin C. Carlisle
1999-09-08  0:00 ` Array of Variant Records Question Matthew Heaney
1999-09-08  0:00   ` Mike Silva
1999-09-08  0:00     ` Matthew Heaney
1999-09-09  0:00       ` Robert Dewar
1999-09-09  0:00         ` Matthew Heaney
1999-09-09  0:00           ` Matthew Heaney
1999-09-09  0:00             ` Mark Lundquist
1999-09-09  0:00             ` Robert Dewar
1999-09-09  0:00           ` Robert Dewar
1999-09-09  0:00             ` Brian Rogoff
1999-09-13  0:00               ` Matthew Heaney [this message]
1999-09-13  0:00                 ` Robert A Duff
1999-09-13  0:00                   ` Matthew Heaney
1999-09-13  0:00                 ` Brian Rogoff
1999-09-14  0:00                   ` Robert Dewar
1999-09-14  0:00                     ` Brian Rogoff
1999-09-14  0:00                   ` Robert Dewar
1999-09-09  0:00             ` Matthew Heaney
1999-09-10  0:00               ` Mark Lundquist
1999-09-10  0:00                 ` Matthew Heaney
1999-09-11  0:00                 ` Robert Dewar
1999-09-10  0:00               ` Robert Dewar
1999-09-10  0:00                 ` Mark Lundquist
1999-09-10  0:00                   ` Matthew Heaney
1999-09-11  0:00                     ` Jean-Pierre Rosen
1999-09-14  0:00                     ` "cast away const" (was Re: Array of Variant Records Question...) Mark Lundquist
     [not found]                     ` <wccd7viiv59.fsf@world.std.com>
1999-09-22  0:00                       ` Array of Variant Records Question Robert I. Eachus
     [not found]                       ` <7rrmqd$l89@drn.newsguy.com>
     [not found]                         ` <wcciu59n2uf.fsf@world.std.com>
1999-09-22  0:00                           ` Robert I. Eachus
1999-09-23  0:00                             ` Robert Dewar
1999-09-23  0:00                               ` Robert I. Eachus
1999-09-11  0:00               ` Richard D Riehle
1999-09-13  0:00                 ` Hyman Rosen
1999-09-14  0:00                 ` Mark Lundquist
     [not found]                   ` <7roohh$s6r@dfw-ixnews7.ix.netcom.com>
     [not found]                     ` <37e01168@news1.prserv.net>
     [not found]                       ` <7rp86o$c6h@dfw-ixnews3.ix.netcom.com>
     [not found]                         ` <37E18CC6.C8D431B@rational.com>
     [not found]                           ` <7rs8bn$s6@dfw-ixnews4.ix.netcom.com>
     [not found]                             ` <wccemfxn15s.fsf@world.std.com>
1999-09-22  0:00                               ` 'constant functions' and access constant params (was Re: Array of Variant Records Question...) Richard D Riehle
     [not found]                             ` <37e2e58c@news1.prserv.net>
1999-09-22  0:00                               ` Richard D Riehle
1999-09-22  0:00                                 ` Mark Lundquist
1999-09-22  0:00                                   ` Mark Lundquist
1999-09-22  0:00                                 ` Matthew Heaney
1999-09-22  0:00                                   ` Richard D Riehle
1999-09-22  0:00                                     ` Matthew Heaney
1999-09-22  0:00                                     ` Matthew Heaney
1999-09-23  0:00                                       ` Vincent Marciante
1999-09-23  0:00                                         ` Matthew Heaney
1999-09-24  0:00                                       ` Robert A Duff
1999-09-25  0:00                                         ` Matthew Heaney
1999-09-27  0:00                                       ` Richard D Riehle
1999-09-27  0:00                                         ` David Kristola
1999-09-27  0:00                                       ` Richard D Riehle
1999-09-23  0:00                                     ` Robert Dewar
1999-09-27  0:00                                       ` Richard D Riehle
1999-09-28  0:00                                         ` Robert Dewar
1999-09-28  0:00                                           ` "Competence" (was: 'constant functions' and access constant params) Ted Dennison
1999-09-28  0:00                                             ` Robert Dewar
1999-09-28  0:00                                         ` 'constant functions' and access constant params (was Re: Array of Variant Records Question...) Robert Dewar
1999-09-28  0:00                                           ` Richard D Riehle
1999-09-29  0:00                                             ` Robert Dewar
1999-09-29  0:00                                             ` Robert A Duff
1999-09-10  0:00             ` Proposed Ada features " Mark Lundquist
1999-09-10  0:00               ` Matthew Heaney
1999-09-10  0:00                 ` tmoran
1999-09-09  0:00     ` Array of Variant Records Question Nick Roberts
1999-09-09  0:00       ` Robert Dewar
1999-09-09  0:00       ` Tucker Taft
1999-09-10  0:00         ` Nick Roberts
replies disabled

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