comp.lang.ada
 help / color / mirror / Atom feed
* Re: scope and visibility
@ 2002-02-27  7:00 Christoph Grein
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Grein @ 2002-02-27  7:00 UTC (permalink / raw)


> but I'm having quite a hard time with 'private' and friends.

The Ada keyword 'private' means that you do not see into the thing denoted as 
private.

Thus a private type hides its details, you do not see them and cannot assume 
anything about them.
'private' in a package hides anything behind from visibility outside this 
hierarchy.

package P is

  type T is private;

  ...operations...

private

  type T is new Integer;

end P;

If you're outside of P, you cannot make use of the fact that T is an integer. It 
could be anything (array, record, ...) that is not limited (another Ada 
keyword).

Inside of P, after the keyword 'private' and also in the body, you of course can 
use the fact that T is Integer. This is also true for children of P.

private package P.Priv_Child is

  -- You see the private part of P here.

private

end P.Priv_Child;

package P.Child is

  -- You do not see the private part of P here.

private

  -- You see the private part of P here.

end P.Child;

This is approximately like (but there _are_ differences):

package P is

  type T is private;

  ...operations...

  package Child is
    ...
  end Child;

private

  type T is new Integer;

  package Priv_Child is
    ...
  end Priv_Child;

end P;



Now try

package P.Priv_Child.Grand_Child is ...

private P.Priv_Child.Priv_Grand_Child is ...

package P.Child.Grand_Child is ...

private P.Child.Priv_Grand_Child is ...

These all have different visibilities.


generic
  type T is private;
package P is
  -- You cannot assume anything about P except that it's not limited and
  -- that it is definite.
end P;



^ permalink raw reply	[flat|nested] 4+ messages in thread
* scope and visibility
@ 2002-02-27  4:00 Dave Poirier
  2002-02-27 15:19 ` Jim Rogers
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Poirier @ 2002-02-27  4:00 UTC (permalink / raw)


this is most certainly a FAQ one, but, I've been reading the Lovelace 
tutorial, tried reading chapter 8 of the ALRM and read the part 
concerning visibility in Ada Distilled.

I understand the difference between 'with' and 'use', that's no problem, 
but I'm having quite a hard time with 'private' and friends.  Is there 
any tutorial detailing from side-to-side how those work for ada-newbies?

The chapter 8 of the ALRM is definately complete but is so full of Ada 
terms that I'd have to spend 10 days pulling my hair going from side to 
side of the book to figure it out.  Most Ada-newbie tutorial teaches you 
how to write basic apps skimming visibility (mostly talk about with/use 
and that's it).

Any url, doc, explanation whatever would be greatly appreciated.  I've 
been trying for the past 4 hours to created a Bounded_String and just 
can't get it.

Thanks,
EKS - Dave Poirier.


note: something nice full of examples using the Ada libraries, with both 
working and non-working examples for all possible combinations and why 
they [don't] work...




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

end of thread, other threads:[~2002-02-27 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-27  7:00 scope and visibility Christoph Grein
  -- strict thread matches above, loose matches on Subject: below --
2002-02-27  4:00 Dave Poirier
2002-02-27 15:19 ` Jim Rogers
2002-02-27 22:47   ` chris.danx

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