comp.lang.ada
 help / color / mirror / Atom feed
* Help with gnat IO
@ 1994-11-28 11:28 Woodrow Yeung
  1994-11-28 18:13 ` Tom Griest
  1994-11-29 22:05 ` Robert Dewar
  0 siblings, 2 replies; 6+ messages in thread
From: Woodrow Yeung @ 1994-11-28 11:28 UTC (permalink / raw)


Hi,

I'm using gnat and am having trouble with the input/output routines.
First of all, how do I use the INTEGER_IO package?  I get this error
message:
file "integer_io.ads" not found
but I see the INTEGER_IO package defined within the a-textio.ads file.
I want to be able to format my field width.

Secondly, in the Ada reference manual (July 1980) there is a function  
GET_STRING that reads a sequence of character up to the next white space.   
This function does not exist in the gnat implementation.  I want to do  
this without writing my own routine.  By using GET, I end up with  
characters filling my string.  Worse yet, I read too much data.  My data  
is composed of lines with fields delimited by whitespace.  (I guess  
GET_STRING got taken out of Ada before it was finalized.)

I would appreciate any help.  By the way, where's all the traffic in
this newsgroup?  Are people still using Ada?

--
Woodrow Yeung
yeung@reed.edu



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

* Re: Help with gnat IO
  1994-11-28 11:28 Help with gnat IO Woodrow Yeung
@ 1994-11-28 18:13 ` Tom Griest
  1994-11-29 22:05 ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Griest @ 1994-11-28 18:13 UTC (permalink / raw)


In article <3bces8$500@scratchy.reed.edu> yeung@bagpipe.reed.edu (Woodrow Yeung) writes:
>Hi,
>
>I'm using gnat and am having trouble with the input/output routines.
>First of all, how do I use the INTEGER_IO package?  I get this error
>message:
>file "integer_io.ads" not found
>but I see the INTEGER_IO package defined within the a-textio.ads file.
>I want to be able to format my field width.
>

Is the a-textio.ads file in a directory specified by the ADA_INCLUDE_PATH
environment variable?  BTW, you should always say what host/target and
compiler revision you are working with.

>Secondly, in the Ada reference manual (July 1980) there is a function  
                                        ^^^^^^^^^
>GET_STRING that reads a sequence of character up to the next white space.   

You're kidding right?  You should sell this rev of the Ada manual
to some collector and download the most recent version of the RM from
the ajpo host.  Make sure you get a 9X version.
 
>This function does not exist in the gnat implementation.  I want to do  
>this without writing my own routine.  By using GET, I end up with  
>characters filling my string.  Worse yet, I read too much data.  My data  
>is composed of lines with fields delimited by whitespace.  (I guess  
>GET_STRING got taken out of Ada before it was finalized.)

Good guess.  It is very difficult to assign unconstrained arrays to
an object when you don't know what the size is.  Of course there are
work-arounds (like dynamic allocation or creating a new declarative scope)
and this type of silly function now exists in several places in 9x. :-(

Use procedure: Get_Line(STR,LINE_LEN);


>
>I would appreciate any help.  By the way, where's all the traffic in
>this newsgroup?  Are people still using Ada?
>

Yes.

-Tom



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

* Re: Help with gnat IO
@ 1994-11-29 17:52 Bennett, Chip (KTR) ~U
  0 siblings, 0 replies; 6+ messages in thread
From: Bennett, Chip (KTR) ~U @ 1994-11-29 17:52 UTC (permalink / raw)


Woodrow Yeung <yeung@BAGPIPE.REED.EDU> wrote:

> I'm using gnat and am having trouble with the input/output routines.
> First of all, how do I use the INTEGER_IO package?  I get this error
> message:
> file "integer_io.ads" not found
> but I see the INTEGER_IO package defined within the a-textio.ads file.
> I want to be able to format my field width.

Remember that INTEGER_IO is a generic package within TEXT_IO.  You "with" in
TEXT_IO and then instantiate your own version of INTEGER_IO:

     with Text_IO; use Text_IO;
     procedure WhoCares is

        type ItemCount is range 0 .. 100;

        package ItemCount_IO is new Integer_IO (ItemCount);
        use ItemCount_IO;

        MyCount : ItemCount := 10;

        package Int_IO is new Integer_IO (Integer);
        use Int_IO;

        Count : Integer := 348;

     begin

        Put (MyCount); -- implicitly uses ItemCount_IO.Put;
        Put (Count); -- implicitly uses Int_IO.Put;

     end WhoCares;

INTEGER_IO is a generic package _because_ there can be many user defined
integer types.  If you already knew all this, it was good practice for me to
tell it anyway.  :-)

*****************************************************************
* Chip Bennett, GDE Systems Inc | BennettC@j64.stratcom.af.mil  *
* USSTRATCOM/J64213             | Voice (402)294-7360           *
* 901 SAC Blvd, Suite 2B24      | FAX   (402)294-7912           *
* Offutt AFB, NE 68113-6600     | Proud member of Team Ada      *
* Opinions expressed here are my own _so_,  TTFWTW              *
*****************************************************************



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

* Re: Help with gnat IO
  1994-11-28 11:28 Help with gnat IO Woodrow Yeung
  1994-11-28 18:13 ` Tom Griest
@ 1994-11-29 22:05 ` Robert Dewar
  1994-12-01  3:10   ` Keith Thompson
  1994-12-01 13:34   ` Bob Duff
  1 sibling, 2 replies; 6+ messages in thread
From: Robert Dewar @ 1994-11-29 22:05 UTC (permalink / raw)


Woodrew, first please read the documentation, which specifically asks
that you send copies of all questions on GNAT to gnat-report@cs.nyu.edu.

Second, if you are reading the July 1980 version of the reference manual,
you qualify as an Ada historian, this is an interim version that was never
finalized, and the final version is different in important respects, so you
had better get a relevant version of the standard. Better still, since you
are obviously running into pretty elementary problems, you will do better
with a good book on Ada, such as the one by John Barnes.

To use integer_io, you must with text_io and then instantiate integer_io
(there will be examples in any Ada text book, follow them). Alternatively
use the string put with Integer'Image(value).

There is no Get_String function (was there really a procedure with that
name in Ada 80??) There are however versions of get that get from a string,
which is presumably what you are looking for. For example:

      procedure Get
        (From : in String;
         Item : out Num;
         Last : out Positive);

this is a subprogram inside the generic package Integer_IO.

I posted this just because I thought people would be entertained at the
idea of an Ada beginner somehow getting hold of the July 1980 version of
the RM! Perhaps we should have burnt all the copies :-)




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

* Re: Help with gnat IO
  1994-11-29 22:05 ` Robert Dewar
@ 1994-12-01  3:10   ` Keith Thompson
  1994-12-01 13:34   ` Bob Duff
  1 sibling, 0 replies; 6+ messages in thread
From: Keith Thompson @ 1994-12-01  3:10 UTC (permalink / raw)


In <3bg8je$hsr@gnat.cs.nyu.edu> dewar@cs.nyu.edu (Robert Dewar) writes:
> There is no Get_String function (was there really a procedure with that
> name in Ada 80??)

Yes.

>                   There are however versions of get that get from a string,
> which is presumably what you are looking for.

I don't think that's what he was looking for.

In fact, Ada 80's Text_IO has two overloaded Get_String functions
(not procedures):

    function GET_STRING(FILE: in IN_FILE) return STRING;
    function GET_STRING return STRING;

	Perform GET operations on the specified in file, skipping any
	leading blanks (that is, spaces, tabulation characters or line
	marks) and returns as result the next sequence of characters up
	to (and not including) a blank.  The default file is the current
	input file.

Likewise, the Get_Line routines were also functions returning STRING;
they now return the string and its 'Last in OUT parameters.

Out of curiosity, why was this change made?  The current version of
Get_Line makes it difficult to read arbitrarily long lines; you have to
decide the maximum length before reading the line.  (At least it behaves
gracefully if the line is longer than the string you provide.)

It looks like GET_STRING would have been a handy thing to have in some
cases, but perhaps a bit too specialized to include in the language;
it shouldn't be too hard to implement it on top of the existing routines.

> I posted this just because I thought people would be entertained at the
> idea of an Ada beginner somehow getting hold of the July 1980 version of
> the RM! Perhaps we should have burnt all the copies :-)

You can have my 1980 RM (and 1979 RM and rationale) when you pry them ...
you know the rest.  8-)}

-- 
Keith Thompson (The_Other_Keith)  kst@alsys.com
TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
/user/kst/.signature: I/O error (core dumped)



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

* Re: Help with gnat IO
  1994-11-29 22:05 ` Robert Dewar
  1994-12-01  3:10   ` Keith Thompson
@ 1994-12-01 13:34   ` Bob Duff
  1 sibling, 0 replies; 6+ messages in thread
From: Bob Duff @ 1994-12-01 13:34 UTC (permalink / raw)


In article <3bg8je$hsr@gnat.cs.nyu.edu>, Robert Dewar <dewar@cs.nyu.edu> wrote:
>There is no Get_String function (was there really a procedure with that
>name in Ada 80??) There are however versions of get that get from a string,
>which is presumably what you are looking for.

No, I don't think that's what the original poster was looking for.  In
Ada 80, there was a *function* Get_String:

    function GET_STRING(FILE: in IN_FILE) return STRING;

This would skip any blanks, then read nonblank characters, and return
everything up to the next blank (a newline is considered a blank).
E.g.:

    foo bar baz-bat

Three calls to GET_STRING would return "foo", "bar", and "baz-bat".

There was also a GET_LINE function, with similar behavior.

Sounds pretty useful.  It was probably deleted because it's a little bit
tricky to implement.  (Where do you buffer the characters, on a system
like Unix, where you can't tell how long the line is until you've read
it?  The current language requires the programmer to answer that
question.)

Other interesting differences in Text_IO: In 1980, IN_FILE and OUT_FILE
were two separate types; the mode business did not exist.  In 1979,
there were I/O procedures for the types INTEGER and FLOAT (instead of
the generic versions).

>I posted this just because I thought people would be entertained at the
>idea of an Ada beginner somehow getting hold of the July 1980 version of
>the RM! Perhaps we should have burnt all the copies :-)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:-)

I have occasionally found pre-1983 versions useful during the design of
Ada 9X.

- Bob
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)



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

end of thread, other threads:[~1994-12-01 13:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-28 11:28 Help with gnat IO Woodrow Yeung
1994-11-28 18:13 ` Tom Griest
1994-11-29 22:05 ` Robert Dewar
1994-12-01  3:10   ` Keith Thompson
1994-12-01 13:34   ` Bob Duff
  -- strict thread matches above, loose matches on Subject: below --
1994-11-29 17:52 Bennett, Chip (KTR) ~U

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