comp.lang.ada
 help / color / mirror / Atom feed
* Help with Text_IO Instantiation!
@ 1996-04-21  0:00 Robert Gelb
  1996-04-22  0:00 ` Robert Dewar
  1996-04-24  0:00 ` John Herro
  0 siblings, 2 replies; 4+ messages in thread
From: Robert Gelb @ 1996-04-21  0:00 UTC (permalink / raw)


I have the following code:

procedure test is 
	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));
end test;		

What kind of Text_IO instatiation do I need to specify in order to make
'put(StrArray(1));' statement work.

I've tried 
	with Ada.Text_Io, Ada.Integer_Text_Io;
	use  Ada.Text_Io, Ada.Integer_Text_Io;
but it doesn't seem to work with the type of string I declared.  I am
using ADA95.




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

* Re: Help with Text_IO Instantiation!
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1996-04-22  0:00 UTC (permalink / raw)


There is no built in Put for user defined string types, you will have
to program it yourself.





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

* Re: Help with Text_IO Instantiation!
  1996-04-24  0:00 ` John Herro
@ 1996-04-24  0:00   ` David Weller
  0 siblings, 0 replies; 4+ messages in thread
From: David Weller @ 1996-04-24  0:00 UTC (permalink / raw)



In article <4llqlg$i49@newsbf02.news.aol.com>,
John Herro <johnherro@aol.com> wrote:
>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?

[Good advice from John trimmed...]
>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

What John means, of course, is that you want to probably do something
like this:
procedure sub is

   subtype Tiny_String is String(1..12);

   type Tiny_Array is array(integer range <>) of Tiny_String;

   TA : Tiny_Array(1..10);
begin
   TA(1) := "Ohmygoodness";
   put_Line(Ta(1));
end sub;

Note that you could not simply declare:
   type Tiny_Array is array(String) of Tiny_String;
Because String is an unconstrained array.

-- 
    Visit the Ada 95 Booch Components Homepage: www.ocsystems.com/booch
           This is not your father's Ada -- lglwww.epfl.ch/Ada




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

* Re: Help with Text_IO Instantiation!
  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
  1996-04-24  0:00   ` David Weller
  1 sibling, 1 reply; 4+ messages in thread
From: John Herro @ 1996-04-24  0:00 UTC (permalink / raw)


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




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

end of thread, other threads:[~1996-04-24  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
1996-04-24  0:00   ` David Weller

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