comp.lang.ada
 help / color / mirror / Atom feed
* What exactly is a 'record' in Ada 95?
@ 2004-09-08 12:27 matthias_k
  2004-09-08 12:58 ` Jim Rogers
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: matthias_k @ 2004-09-08 12:27 UTC (permalink / raw)


Hello,

I have to do some research for university about the Ada language,
but I have to learn it from scratch. There's a good chance that
I will be here over the next couple weeks asking questions about
things that may be trivial for an experienced Ada programmer --
deal with it :)

So, what is a 'record' in Ada? Do I have to think about it like
a struct in C? It seems to serve the same purpose. Is 'record' the
only type modifier? Where are the differences?

Thanks in advance,
- Matthias Kaeppler



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
@ 2004-09-08 12:58 ` Jim Rogers
  2004-09-08 18:05   ` matthias_k
  2004-09-08 13:12 ` Marc A. Criley
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Jim Rogers @ 2004-09-08 12:58 UTC (permalink / raw)


matthias_k <nospam@digitalraid.com> wrote in news:chmtr8$6lp$06$1@news.t-
online.com:

> So, what is a 'record' in Ada? Do I have to think about it like
> a struct in C? It seems to serve the same purpose. Is 'record' the
> only type modifier? Where are the differences?

A record is similar to a struct in C. It is not, however, exactly
the same. Ada records can have a few features not available to C
structs.

An Ada record can have one or more discriminants which are used to
discriminate between structural representations. The following 
example may be helpful.

type Gender_Type is (Male, Female);

type Person (Gender : Gender_Type) is record
   Name : Name_String;
   Age  : Natural;
   case Gender is
      when Male => 
         Beard_Length : Natural;
      when Female => 
         null;
   end case;
end record;

The first type definition defines an enumeration type.
The second type definition defines a record type with a 
discriminant. In this example, all Persons have a name
and age. A person that is Male also has a Beard_Length.

Discriminant records were introduced in Ada 83. They are
not used much in Ada 95. Ada 95 introduced the concept of
tagged types, which are frequently used instead of 
discriminant types. A tagged type is an extensible record
supporting inheritance.

type Person is tagged record
   Name : Name_String;
   Age  : Natural;
end record;

type Male is new Person with record
   Beard_Length : Natural;
end record;

Type Male inherits all the attributes of Person and adds
Beard_Length.


Records are not the only way to specify a type in Ada. 
Ada allows you to specify array types and what other
languages designate as primitive types.

type Ratings is range 1..10;

type Real is digits 15;

type Volt is delta 0.125 range 0.0 .. 255.0; 

type Money is delta 0.02 digits 10;

type Days is (Sunday, Monday, Tuesday, Wednesday,
              Thursday, Friday, Saturday);

type Daily_Sales is array(Days) of Money;

Jim Rogers





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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
  2004-09-08 12:58 ` Jim Rogers
@ 2004-09-08 13:12 ` Marc A. Criley
  2004-09-08 18:08   ` matthias_k
  2004-09-08 13:30 ` Peter Hermann
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Marc A. Criley @ 2004-09-08 13:12 UTC (permalink / raw)


"matthias_k" <nospam@digitalraid.com> wrote:

> I have to do some research for university about the Ada language,
> but I have to learn it from scratch. There's a good chance that
> I will be here over the next couple weeks asking questions about
> things that may be trivial for an experienced Ada programmer --
> deal with it :)
>
> So, what is a 'record' in Ada? Do I have to think about it like
> a struct in C? It seems to serve the same purpose. Is 'record' the
> only type modifier? Where are the differences?

While we'll be glad to help answer your questions, I think you'll be
ill-served if you attempt to learn about the language by posting disjoint
questions about the various syntactic and semantic pieces that define it.

I'd encourage you to take just a few hours to go over some on-line Ada
training material to give you a coherent overview of the language, and then
we'll help in those areas in which you have questions or need to have the
blanks filled in. A basic understanding of the language on your part will
help give us some common understanding and terminology that will help in
your research.

So here's a pointer to a collection of on-line Ada resources, which includes
both complete books and tutorials: www.adapower.com/learn

Come back soon!

Marc A. Criley
McKae Technologies
www.mckae.com





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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
  2004-09-08 12:58 ` Jim Rogers
  2004-09-08 13:12 ` Marc A. Criley
@ 2004-09-08 13:30 ` Peter Hermann
  2004-09-08 18:09   ` matthias_k
  2004-09-08 13:40 ` Georg Bauhaus
  2004-09-08 18:22 ` Dmitry A. Kazakov
  4 siblings, 1 reply; 11+ messages in thread
From: Peter Hermann @ 2004-09-08 13:30 UTC (permalink / raw)




To: matthias_k@digitalraid.com   bounces!


matthias_k <nospam@digitalraid.com> wrote:
> but I have to learn it from scratch. There's a good chance that

Lieber Matthias Kaeppler,
es gibt jede Menge Tutorials (siehe meine resources_on_ada.html).
Meine Empfehlung waere, sich erst einmal dort einzulesen.
In comp.lang.ada bist Du zwar immer willkommen,
aber die dortigen Statuten sollte man besser einhalten,
sonst verliert diese Newsgroup ihren Sinn.
Gruss,
Peter Hermann

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
                   ` (2 preceding siblings ...)
  2004-09-08 13:30 ` Peter Hermann
@ 2004-09-08 13:40 ` Georg Bauhaus
  2004-09-08 18:22 ` Dmitry A. Kazakov
  4 siblings, 0 replies; 11+ messages in thread
From: Georg Bauhaus @ 2004-09-08 13:40 UTC (permalink / raw)


matthias_k <nospam@digitalraid.com> wrote:
: So, what is a 'record' in Ada? Do I have to think about it like
: a struct in C? It seems to serve the same purpose. Is 'record' the
: only type modifier? Where are the differences?

For values of a record type, there are useful notations.
For example, a two component record value might be written as

  (name => "Frank", age => 56)

or alternatively

  (age => 56, name => "Frank")

or alternatively

  Person'(name => "Frank", age = 56)

or altenatively

  Person'("Frank", 56)

or just

  ("Frank", 56)


I'll leave it to you to find out what other alternatives there are,
if any.
In any case the compiler will check that _all_ record components get
values.

-- Georg




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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 12:58 ` Jim Rogers
@ 2004-09-08 18:05   ` matthias_k
  0 siblings, 0 replies; 11+ messages in thread
From: matthias_k @ 2004-09-08 18:05 UTC (permalink / raw)


Jim Rogers wrote:
> matthias_k <nospam@digitalraid.com> wrote in news:chmtr8$6lp$06$1@news.t-
> online.com:
> 
> 
>>So, what is a 'record' in Ada? Do I have to think about it like
>>a struct in C? It seems to serve the same purpose. Is 'record' the
>>only type modifier? Where are the differences?
> 
> 
> A record is similar to a struct in C. It is not, however, exactly
> the same. Ada records can have a few features not available to C
> structs.
> 
> An Ada record can have one or more discriminants which are used to
> discriminate between structural representations. The following 
> example may be helpful.
> 
> type Gender_Type is (Male, Female);
> 
> type Person (Gender : Gender_Type) is record
>    Name : Name_String;
>    Age  : Natural;
>    case Gender is
>       when Male => 
>          Beard_Length : Natural;
>       when Female => 
>          null;
>    end case;
> end record;
> 
> The first type definition defines an enumeration type.
> The second type definition defines a record type with a 
> discriminant. In this example, all Persons have a name
> and age. A person that is Male also has a Beard_Length.
> 
> Discriminant records were introduced in Ada 83. They are
> not used much in Ada 95. Ada 95 introduced the concept of
> tagged types, which are frequently used instead of 
> discriminant types. A tagged type is an extensible record
> supporting inheritance.
> 
> type Person is tagged record
>    Name : Name_String;
>    Age  : Natural;
> end record;
> 
> type Male is new Person with record
>    Beard_Length : Natural;
> end record;
> 
> Type Male inherits all the attributes of Person and adds
> Beard_Length.
> 
> 
> Records are not the only way to specify a type in Ada. 
> Ada allows you to specify array types and what other
> languages designate as primitive types.
> 
> type Ratings is range 1..10;
> 
> type Real is digits 15;
> 
> type Volt is delta 0.125 range 0.0 .. 255.0; 
> 
> type Money is delta 0.02 digits 10;
> 
> type Days is (Sunday, Monday, Tuesday, Wednesday,
>               Thursday, Friday, Saturday);
> 
> type Daily_Sales is array(Days) of Money;
> 
> Jim Rogers
> 
> 

Thanks Jim for this detailed answer. Appreciated.



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 13:12 ` Marc A. Criley
@ 2004-09-08 18:08   ` matthias_k
  0 siblings, 0 replies; 11+ messages in thread
From: matthias_k @ 2004-09-08 18:08 UTC (permalink / raw)


Marc A. Criley wrote:
> "matthias_k" <nospam@digitalraid.com> wrote:
> 
> 
>>I have to do some research for university about the Ada language,
>>but I have to learn it from scratch. There's a good chance that
>>I will be here over the next couple weeks asking questions about
>>things that may be trivial for an experienced Ada programmer --
>>deal with it :)
>>
>>So, what is a 'record' in Ada? Do I have to think about it like
>>a struct in C? It seems to serve the same purpose. Is 'record' the
>>only type modifier? Where are the differences?
> 
> 
> While we'll be glad to help answer your questions, I think you'll be
> ill-served if you attempt to learn about the language by posting disjoint
> questions about the various syntactic and semantic pieces that define it.
> 
> I'd encourage you to take just a few hours to go over some on-line Ada
> training material to give you a coherent overview of the language, and then
> we'll help in those areas in which you have questions or need to have the
> blanks filled in. A basic understanding of the language on your part will
> help give us some common understanding and terminology that will help in
> your research.
> 
> So here's a pointer to a collection of on-line Ada resources, which includes
> both complete books and tutorials: www.adapower.com/learn
> 
> Come back soon!
> 
> Marc A. Criley
> McKae Technologies
> www.mckae.com
> 
> 

Yes, of course I am reading several guides and ebooks about Ada. I'm 
currently working through "Ada Distilled" by Richard Riehle and Barne's 
"Overview of the Ada Language". It's just that the 'record' keyword was 
mentioned early in the books but wasn't clearly explained. I won't be 
asking about every single keyword, no worries :)

Tanks for that link by the way.



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 13:30 ` Peter Hermann
@ 2004-09-08 18:09   ` matthias_k
  2004-09-09 12:06     ` Peter Hermann
  2004-09-18  4:14     ` Richard Pennington
  0 siblings, 2 replies; 11+ messages in thread
From: matthias_k @ 2004-09-08 18:09 UTC (permalink / raw)


Peter Hermann wrote:
> To: matthias_k@digitalraid.com   bounces!
> 
> 
> matthias_k <nospam@digitalraid.com> wrote:
> 
>>but I have to learn it from scratch. There's a good chance that
> 
> 
> Lieber Matthias Kaeppler,
> es gibt jede Menge Tutorials (siehe meine resources_on_ada.html).
> Meine Empfehlung waere, sich erst einmal dort einzulesen.
> In comp.lang.ada bist Du zwar immer willkommen,
> aber die dortigen Statuten sollte man besser einhalten,
> sonst verliert diese Newsgroup ihren Sinn.
> Gruss,
> Peter Hermann
> 
Danke f�r Deine Antwort :)
Wo genau kann ich Deine Linksammlung finden?

Gru�
Matthias



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
                   ` (3 preceding siblings ...)
  2004-09-08 13:40 ` Georg Bauhaus
@ 2004-09-08 18:22 ` Dmitry A. Kazakov
  4 siblings, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-08 18:22 UTC (permalink / raw)


On Wed, 08 Sep 2004 14:27:32 +0200, matthias_k wrote:

> ... Is 'record' the only type modifier?

It depends on what you count under type modifiers. Very roughly Ada's "type
modifiers":

abstract - abstract type = it has no instances (values), "interface"
access - pointer
aliased - values can be referenced (can get a pointer to)
all - target values can be in any storage pool
array - true array
class - class-wide type (has polymorphic values)
delta / digits - used for real numbers to specify precision
in / in out / out - standard subtypes of subroutine parameters
limited - type which values cannot be copied
mod - used with modular numbers
new - a type clone
new...with - a type extension
null record - has no members, empty record
private - a type which implementation is hidden
protected - a type which values are concurrently used in a safe way
range - used with numeric types to specify values range 
record - has members, but not protected
tagged - a class member type (see class above), an extensible type
task - values are active objects, "threads"

-- 
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 18:09   ` matthias_k
@ 2004-09-09 12:06     ` Peter Hermann
  2004-09-18  4:14     ` Richard Pennington
  1 sibling, 0 replies; 11+ messages in thread
From: Peter Hermann @ 2004-09-09 12:06 UTC (permalink / raw)


> > To: matthias_k@digitalraid.com   bounces!



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

* Re: What exactly is a 'record' in Ada 95?
  2004-09-08 18:09   ` matthias_k
  2004-09-09 12:06     ` Peter Hermann
@ 2004-09-18  4:14     ` Richard Pennington
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Pennington @ 2004-09-18  4:14 UTC (permalink / raw)


matthias_k wrote:

> Peter Hermann wrote:
> 
>> To: matthias_k@digitalraid.com   bounces!
>>
>>
>> matthias_k <nospam@digitalraid.com> wrote:
>>
>>> but I have to learn it from scratch. There's a good chance that
>>
>>
>>
>> Lieber Matthias Kaeppler,
>> es gibt jede Menge Tutorials (siehe meine resources_on_ada.html).
>> Meine Empfehlung waere, sich erst einmal dort einzulesen.
>> In comp.lang.ada bist Du zwar immer willkommen,

Shouldn't that be "sind Sie", or do you guys know each other? ;-)
Maybe things have changed since I was in Germany last time.

>> aber die dortigen Statuten sollte man besser einhalten,
>> sonst verliert diese Newsgroup ihren Sinn.
>> Gruss,
>> Peter Hermann
>>
> Danke f�r Deine Antwort :)
> Wo genau kann ich Deine Linksammlung finden?
> 
> Gru�
> Matthias

Sorry about the extreme offtopicness... It's late on a Friday night.

-Rich

-- 
Richard Pennington
Email: rich@pennware.com
http://www.pennware.com ftp://ftp.pennware.com



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

end of thread, other threads:[~2004-09-18  4:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
2004-09-08 12:58 ` Jim Rogers
2004-09-08 18:05   ` matthias_k
2004-09-08 13:12 ` Marc A. Criley
2004-09-08 18:08   ` matthias_k
2004-09-08 13:30 ` Peter Hermann
2004-09-08 18:09   ` matthias_k
2004-09-09 12:06     ` Peter Hermann
2004-09-18  4:14     ` Richard Pennington
2004-09-08 13:40 ` Georg Bauhaus
2004-09-08 18:22 ` Dmitry A. Kazakov

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