comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Help with Text_IO Instantiation!
Date: 1996/04/24
Date: 1996-04-24T00:00:00+00:00	[thread overview]
Message-ID: <4llqlg$i49@newsbf02.news.aol.com> (raw)
In-Reply-To: 4lc67p$jeh@hatathli.csulb.edu

rgelb@csulb.edu (Robert Gelb) wrote:
> type string is array(integer range 1..10) of character;
> type SaType is array(integer range <>) of string;
> StrArray:SaType(1..5);
> begin
>    put(StrArray(1));.
> What kind of Text_IO instatiation do I need to
> make 'put(StrArray(1));' work?
     Robert Dewar's answer is entirely correct, but allow me to add some
comments.  In writing
type string is array(integer range 1 .. 10) of character;
you're doing two potentially confusing things which beginners should avoid
and even veteran programmers should do very rarely, if at all.  First,
you've chosen a name, string, which is *already defined* by the Ada
language.  In doing this, you "hide" the definition of String built into
Ada, namely
type String is array(Integer range <>) of Character;
This is asking for confusion.  You don't need to declare type String in
your program because it's already defined by the language.  Second, you
declared a new *type* when it appears that what you want to declare is a
*subtype*.  Since you use your declaration only in the following line to
declare SaType, I think what you meant to do was:
subtype String10 is String(1 .. 10);
type SaType is array(Integer range <>) of String10;
Now your Put statement will work fine, with no instantiations necessary. 
Incidentally, it's legal to combine the above two lines into one as
follows:
Type SaType is array(Integer range <>) of String(1 .. 10);
Also, note that Ada.Text_IO itself is not generic, but ready-to-use for
the type String built into the language.  Therefore, Ada.Text_IO itself
needs no instantiation.  Inside Ada.Text_IO are generic packages for
integers, floats, enumeration types, etc. that can be instantiated with
approprate user-defined types, but there's no package ready to be
instantiated with a user-defined string type, because you would rarely, if
ever, want to define your own string type.  *Subtypes* of the built-in
type String are perfectly OK, and, since subtypes do not create a new
type, Ada.Text_IO works fine for them.
     I hope this helps, and I hope it clears up more confusion than it
causes!
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-21  0:00 Help with Text_IO Instantiation! Robert Gelb
1996-04-22  0:00 ` Robert Dewar
1996-04-24  0:00 ` John Herro [this message]
1996-04-24  0:00   ` David Weller
replies disabled

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