comp.lang.ada
 help / color / mirror / Atom feed
* Ada 0y wish list: "with private"
@ 2001-02-12 13:41 Thierry Lelegard
  2001-02-13  0:10 ` Keith Thompson
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Thierry Lelegard @ 2001-02-12 13:41 UTC (permalink / raw)


Recently, several wishlist items for Ada 0y were posted in c.l.a.
Like many old Ada users, I have a couple of them. I would like to
propose one for discussion: a "with private" extension.

The idea is to specify in a context clause of a unit spec that an
external unit can be used only in the private part.

Example:

with A;
with private B;
package C is
   X : A.TA;
private
   Y : B.TB; -- legal only in private part
end C;

There are two advantages:

1) Readability. The user of package C is only interested in the public
   interface of C. Reading "with private B", the user knows that he may
   safely ignore what the strange unit B is all about.

2) Use of private packages in private parts. Example:

package Lib is ...

private package Lib.Internals is ....

with private Lib.Internals;
package Lib.Public is
    ....
private
    type TP is new Lib.Internals.TI ...
end Lib.Public;

The second point is, of course, more important than the first one. Some
of my recent code could have been much simpler with such a possibility.
In Ada 95, a private package cannot be referenced at all in the spec
of a public package, even in the private part, since the context clause
"with Lib.Internals" is simply refused.

Two points:
- The "with private" syntax is, of course, only a suggestion.
- Maybe there is some implementation flaw that I missed.

Any ideas or objections?
-Thierry
____________________________________________________________________________

Thierry Lelegard, "The Jazzing Troll", Email: thierry.lelegard@canal-plus.fr
CANAL+ Technologies, 34 place Raoul Dautry, 75516 Paris Cedex 15, France
Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65 75
____________________________________________________________________________





^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: Ada 0y wish list: "with private"
@ 2001-02-15  1:04 Beard, Frank
  2001-02-15  4:18 ` Jeffrey Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Beard, Frank @ 2001-02-15  1:04 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

I would love to see this added to the language.  What I have
long wished for is to be able to do the following:

   package A is

      type B is private;

   private

      type B;  -- If the completion is not here,
               -- then it's deferred to the body

   end A;

   package body A is

      type B is ...;

   end A;

This would allow the separation of the spec and body without
the bother of using an access type, and the associated dangling
memory and garbage collection issues.

While Dr. Wrigley indicated that it could be in a separate
file, I'm not sure if what I described above is what he meant
or if he's talking about a separate off of the spec.  But, I
would have not problem with it being required to be in the
package body.

Frank


-----Original Message-----
From: Dr Adrian Wrigley [mailto:amtw@linuxchip.demon.co.uk]

I'd like something a bit similar. "separate" for the private part.
This would allow the private part to be (for example) in a separate
file.  It could have its own context clause, thus obviating the
need for the "with private" extension.

I think the separation of the private part would make it easier
to separate the specification from the implementation properly.
For example, you usually need to edit the specification when
writing the implementation.  Project architects could forbid
this (keep the spec read-only) if the private was separate.





^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: Ada 0y wish list: "with private"
@ 2001-02-15  4:53 Christoph Grein
  0 siblings, 0 replies; 12+ messages in thread
From: Christoph Grein @ 2001-02-15  4:53 UTC (permalink / raw)
  To: comp.lang.ada

   package A is

      type B is private;

   private

   end A;

   package body A is

      type B is ...;

   end A;

There are severe code generation problem with this proposal. When the spec of A 
is compiled, the compiler has to know how big objects of type B are. So the full 
declaration has to go into the spec.

   package A is

      type B is private;

   private

      type X;
      type B is access X;

   end A;

   package body A is

      type X is ...;

   end A;

With this solution, it's definitely clear how big B is, irrespective of the size 
of X;





^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: Ada 0y wish list: "with private"
@ 2001-02-15 19:16 Beard, Frank
  0 siblings, 0 replies; 12+ messages in thread
From: Beard, Frank @ 2001-02-15 19:16 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

I disagree.  If the compiler treated the deferred type
as a "by reference" type then there wouldn't be a problem.
It would be similar to an access type without the requirement
of allocation/deallocation, null checks, etc.

When a variable of type B is declared, the compiler will
always pass it by reference (by address), which is the
equivalent of passing an access type.

Frank

-----Original Message-----
From: Christoph Grein [mailto:christoph.grein@eurocopter.de]
Sent: Wednesday, February 14, 2001 11:54 PM
To: comp.lang.ada@ada.eu.org
Subject: RE: Ada 0y wish list: "with private"


   package A is

      type B is private;

   private

   end A;

   package body A is

      type B is ...;

   end A;

There are severe code generation problem with this proposal. When the spec
of A 
is compiled, the compiler has to know how big objects of type B are. So the
full 
declaration has to go into the spec.





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2001-02-15 19:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
2001-02-13  0:10 ` Keith Thompson
2001-02-13  0:13 ` Jeff Creem
2001-02-13  6:37   ` Dale Stanbrough
2001-02-13 12:01     ` Jeff Creem
2001-02-13  8:48 ` Dr Adrian Wrigley
2001-02-13  8:56 ` Michel Gauthier
2001-02-13 16:31 ` Ehud Lamm
  -- strict thread matches above, loose matches on Subject: below --
2001-02-15  1:04 Beard, Frank
2001-02-15  4:18 ` Jeffrey Carter
2001-02-15  4:53 Christoph Grein
2001-02-15 19:16 Beard, Frank

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