comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Get_Line problem (GNAT bug?)
Date: Thu, 07 Dec 2006 17:35:00 -0500
Date: 2006-12-07T17:35:00-05:00	[thread overview]
Message-ID: <wcck613tjvv.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1165513333.321151.74320@73g2000cwn.googlegroups.com

"Adam Beneschan" <adam@irvine.com> writes:

> Steve wrote:
>> "Maciej Sobczak" <no.spam@no.spam.com> wrote in message
>> news:el6jss$268$1@cernne03.cern.ch...
>> [snip]
>> >
>> > Any thoughts?
>> >
>> You have run across what I consider to be a weakness in the standard Text_IO
>> library, it is one of the few things I find really annoying about Ada, which
>> I really like otherwise.
>>
>> In Ada you can't write a simple program to read and process lines in a text
>> file that looks something like:
>>
>> while not End_Of_File( inFile ) loop
>>     Get_Line( inFile, Input_Buffer, Count );
>>     Process_Line( Input_Buffer( 1 .. Count ) );
>> end loop;
>>
>> The problem is that Get_Line reads a line of text into a string buffer and
>> returns the count of characters read.

Another problem is that this encourages programmers to place arbitrary
limitations on things (line length in this case -- there's no sensible
way to choose the length of Input_Buffer).

In Ada 2005, you can use the Get_Line function:

    Input_Buffer: constant String := Get_Line(inFile);

which returns the line, however long it is.  (Well, there's still an
arbitrary limitation, if your disk can hold 100 gigabytes, but String can
hold only 2**31-1 bytes.  Oh well, at least that limitation is not quite
so severe.  ;-))

There are many problems with the design of Text_IO...

> It's a mistake to think of a line terminator as a "character"; this is
> probably a common mistake among those used to using C and Unix (or
> Linux or other OS's ending in "x") (or Solaris), but it's not even
> correct to say that a line terminator is a character on other OS's.  On
> Windows, it's two characters (CR-LF).  VMS, as I recall, doesn't use
> any character as a line terminator, but keeps information on where
> lines start and how long they are in an index or somewhere.  Ada is a
> portable language that needs to be implementable on all these systems
> and others, so therefore it left the definition of "line terminator" up
                 ^^^^^^^^^
> to the implementation and did not tie us to the concept that there has
> to be a "character" involved.

I believe the above is historically correct, but I don't buy the
"therefore" above.  For portability, Ada requires the implementation to
translate from whatever OS conventions to Ada's conventions.  It could
just as well have required translating to the Unix convention instead of
translating the rather record-oriented style of Text_IO.  The Unix
convention has certain advantages.

- Bob



      reply	other threads:[~2006-12-07 22:35 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06 14:25 Get_Line problem (GNAT bug?) Maciej Sobczak
2006-12-06 18:06 ` Adam Beneschan
2006-12-06 20:34 ` Gautier
2006-12-06 21:47 ` Dmitry A. Kazakov
2006-12-06 23:40   ` Adam Beneschan
2006-12-07  0:02     ` Björn Persson
2006-12-07  1:09       ` Adam Beneschan
2006-12-07  1:28         ` Björn Persson
2006-12-07  5:00         ` Jeffrey R. Carter
2006-12-07  8:26   ` Maciej Sobczak
2006-12-07  9:21     ` Jean-Pierre Rosen
2006-12-07 13:35       ` Ludovic Brenta
2006-12-07 22:23       ` Robert A Duff
2006-12-07 10:22     ` Dmitry A. Kazakov
2006-12-07 14:51       ` Maciej Sobczak
2006-12-07 16:29         ` Dmitry A. Kazakov
2006-12-08  8:22           ` Maciej Sobczak
2006-12-07 22:50       ` Robert A Duff
2006-12-08  0:13         ` Randy Brukardt
2006-12-08  4:04         ` Larry Kilgallen
2006-12-08  9:11         ` Dmitry A. Kazakov
2006-12-07  9:14   ` Jean-Pierre Rosen
2006-12-07  3:34 ` Steve
2006-12-07 17:42   ` Adam Beneschan
2006-12-07 22:35     ` Robert A Duff [this message]
replies disabled

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