comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Proper program structure
Date: Thu, 1 Oct 2009 00:35:25 -0700 (PDT)
Date: 2009-10-01T00:35:25-07:00	[thread overview]
Message-ID: <274da2eb-d82f-4751-bc82-2753d0e0ec40@l13g2000yqb.googlegroups.com> (raw)
In-Reply-To: 2c37ff49-5419-42db-8d93-675757848082@e4g2000prn.googlegroups.com

On 1 Paź, 01:43, Adam Beneschan <a...@irvine.com> wrote:

> Just for the record, I've had occasion in the past to believe that
> this should be allowed:
>
>    type Car is limited record
>       Gear_Box : aliased Gear_Box_Type;
>       Engine   : Engine_Type (Car.Gear_Box'Access);
>    ...

Yes, that was one of my ideas.

> Anyway, maybe this will motivate me to take a second look at
> that earlier program and perhaps submit a proposal for a new language
> feature.

If we are at potential language proposals, then my problem would be
also solved with some conceptual combination of limited with and
private child packages.

Imagine that Car's components are defined in their private child
packages (Car.Engine, Car.Gear_Box, etc.). These packages are withed
by Car. Now, to avoid the cyclic dependency between package and its
children, I would need to somehow express that the specification of
the child package does not need to see the parent anymore than on the
"limited" basis, whereas the body of the child package would still
have a choice to see the parent spec completely.
To be more exact:

with Cars.Engine;   -- not possible today
with Cars.Gear_Box;
package Cars is
   ...
private
   type Car is record
      Engine : Engine_Type (Car'Access);
      Gear_Box : Gear_Box_Type (Car'Access);
   end record;
end Cars;

-- now the new magic child spec
limited private package Cars.Engine is
   type Engine_Type (C : access Car) is ...
end Cars.Engine;

-- and the new magic child body
with Cars;  -- necessary for a complete view of Cars
with Cars.Gear_Box;
package body Cars.Engine is
   procedure Run (E : in out Engine_Type) is
   begin
      E.C.all.Gear_Box.Move_This_As_Well;
   end Run;
end Cars.Engine;

Note:

1. parent package Cars withs its child package Engine, so that it can
use Engine_Type as component of the Car

2. specification of child package Cars.Engine does not see anything
more than a limited view on its parent's types, so it can use access
to Car

3. body of child package Cars.Engine can see complete parent spec,
because it withs Cars explicitly

Technically it should be possible to compile everything without
cycles.

The whole magic comes down to the additional form of childhood, where
the child does not fully depend on the parent. In other words, the
same trick that is used in Ada2005 to cut cyclic dependencies between
peers (limited with) could be also used to cut cyclic dependencies
between parents and their children.

That would be awesome and would allow me to write Ada in Ada.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



  reply	other threads:[~2009-10-01  7:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-30 21:25 Proper program structure Maciej Sobczak
2009-09-30 22:16 ` Robert A Duff
2009-10-01  7:13   ` Maciej Sobczak
2009-09-30 23:43 ` Adam Beneschan
2009-10-01  7:35   ` Maciej Sobczak [this message]
2009-10-01  6:34 ` Brad Moore
2009-10-01  7:44   ` Maciej Sobczak
2009-10-01  9:39   ` Maciej Sobczak
2009-10-01 15:36     ` Brad Moore
2009-10-01 20:01       ` Maciej Sobczak
2009-10-02  5:44         ` Brad Moore
2009-10-02 13:10           ` Brad Moore
2009-10-01  8:08 ` Dmitry A. Kazakov
replies disabled

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