comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: about abstract data types and pointer
Date: 1996/09/24
Date: 1996-09-24T00:00:00+00:00	[thread overview]
Message-ID: <3247DB70.64F4@gsfc.nasa.gov> (raw)
In-Reply-To: R.3244B03D.32EA@er.uqam.ca


Benoit Rochefort wrote:
> 
> Hi! I'm new with ADA but i'm a programmer since a long time.
> 
> I use the ADA83 standard (but with the gnat compiler than can compile
> ADA95).

Most of what you want is available in Ada95, but not in Ada83. See the
Ada95 reference manual and rational, on-line at:
http://lglsun.epfl.ch/Ada/

Another good reference is "Ada as a Second Language", by Norman Cohen,
available at good bookstores.

> 1- Is there a way to define a procedure type like in MODULA-2 in
>    a way such:
> 
>      TYPE PROC IS PROCEDURE(IN E:ELEMENT);

only in Ada 95 (since you don't want Ada83 generics). See LRM 3.10,
access to subprogram types.
 
> 2- Is there a way to totally hide the representation of an abstract
>    data type in the specification package? 

This is possible in Ada 83:

package Abstraction is
   type Hidden is private;

private
   type Totally_Hidden;
   type Hidden is access Totally_Hidden;
end Abstraction;

package body Abstraction is
   type Totally_Hidden is
   record
      ...
   end record;
end Abstraction;

The full declaration of type Totally_Hidden can be defered to the body,
since the clients of Abstraction only need to know that type Hidden is a
pointer.

> 
> 3- Is there a way to "add" or change attributes to a new type that i
>    have elaborated as an abstract data type (in a package).
> 
>    Ex: L'First could have another meaning here if L is a List.
>        List'Nb could denote the number of elements of a List L.
> 
>    I know i can (and sure i must) code these as functions but i just
>    want to use them as attribute; which could be much more natural here.
> 
>    Is that what RENAMES is for?

In Ada95, the compiler vendor can define new attributes, and you can
provide new functions for any defined attributes, but you can't define
your own new attributes.

In Ada83, you cannot provide new functions for attributes.

> 4- Is there a way to overload the ":=" operator if List is a
>    limited private type?

Not in Ada83. In Ada95, you can derive a type from Controlled, and then
define the subprograms Initialize, Adjust, and Finalize, which are
called at appropriate times during assignment. This turns out to be
better structured than directly overloading ":=". See Chapter 12.5 in
"Ada as a Second Language", or LRM 7.6

> 5- Do the ADA83 standard specify that the deallocation of memory is
>    automatically done? Or must I ensure that my program does it?

Ada83 and Ada95 both allow the compiler vendor to implement garbage
collection (I don't know of any that do). You can implement your own via
Unchecked_Deallocation.

> 
> 6- Now the easy one.
>    Is there a function or procedure to read a character on the
>    keyboard without the need to press enter WHICH IS DEFINED ON THE
>    STANDARD (independant of the used compiler and machine).

No. In Ada95, Text_IO.Get_Immediate is recommended (but not required) to
have this behaviour. I believe the latest version of gnat implements it
this way on most platforms.

> 
> I know that's a lot of questions to answer but that would be VERY
> appreciated.

No problem; I learned a lot from reading this group, and I'm pleased to
be able to return something.

> 
> Please reply by mail. Thank you.

Sorry, if you want to benefit from the community, you have to be a
member!

> Benoit Rochefort
> jk791840@er.uqam.ca

-- 
- Stephe
Stephen.Leake@gsfc.nasa.gov




  parent reply	other threads:[~1996-09-24  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-21  0:00 about abstract data types and pointer Benoit Rochefort
1996-09-24  0:00 ` Norman H. Cohen
1996-09-24  0:00 ` Stephen Leake [this message]
1996-09-24  0:00 ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
1996-09-21  0:00 Benoit Rochefort
replies disabled

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