comp.lang.ada
 help / color / mirror / Atom feed
From: Marin David Condic <condicma@bogon.pwfl.com>
Subject: Re: Strings and reading from a file
Date: 1999/05/13
Date: 1999-05-13T00:00:00+00:00	[thread overview]
Message-ID: <373B271F.EA28F9C8@pwfl.com> (raw)
In-Reply-To: 7hf611$16i$1@cnn.Princeton.EDU

Martin C. Carlisle wrote:
> 
> I can't imagine!  Probably something more like:
> 
> function Next_Line(File : in Ada.Text_IO.File_Type :=
>    Ada.Text_Io.Standard_Input) return String is
>    Answer : String(1..256);
>    Last   : Natural;
> begin
>    Ada.Text_IO.Get_Line(File => File,
>       Item => Answer,
>       Last => Last);
>    if Last = Answer'Last then
>       return Answer & Next_Line;
>    else
>       return Answer(1..Last);
>    end if;
> end Next_Line;
> 
This is a very clever and much more general solution than my original
code segment. (I must confess, I've seen this idiom before.) It has the
decided advantage that it will work for any length line and coupled with
the Unbounded_String type makes the most "polished" answer to the
original post. (If Cameron Hodge is still listening?) Obviously, it will
not incur any recursion overhead for most lines, so it has efficiency
working for it as well.

However - enamoured as I am with the "perfect" solution that works for
any case that may arise - I'd wonder if in practice it isn't a bit of
overkill. In my experience with text files, most lines are less than the
80 character width of a punchcard or glass-teletype. Probably 95% of
text lines are within twice that number. I can't recall ever seeing a
text line (in a standard text file like what would be used for some word
processing app - not a custom data file) which ever exceeded a 256 byte
string. 

Perhaps I'll have to dig up my newly minted statistics library and hack
together a little program to produce the descriptive statistics on line
length from some collection of text files - just so I know what length
to pick to get me to Six Sigma on the "defect rate"? Or would that
constitute proof that I have way too much time on my hands? (Well at
least its not as bad as the web page where someone translated the King
James Version of the Bible into Pig Latin! :-)

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
***To reply, remove "bogon" from the domain name.***

Visit my web page at: http://www.flipag.net/mcondic




  parent reply	other threads:[~1999-05-13  0:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-12  0:00 Strings and reading from a file Cameron Hodge
1999-05-11  0:00 ` David Botton
1999-05-12  0:00 ` Gautier
1999-05-12  0:00 ` Robert Dewar
1999-05-12  0:00   ` Cameron Hodge
1999-05-12  0:00     ` Marin David Condic
1999-05-12  0:00       ` Tom Moran
1999-05-12  0:00         ` Marin David Condic
1999-05-13  0:00       ` jrcarter001
1999-05-13  0:00         ` dennison
1999-05-13  0:00           ` Martin C. Carlisle
1999-05-13  0:00             ` David Botton
1999-05-13  0:00               ` David Botton
1999-05-14  0:00               ` Jean-Pierre Rosen
1999-05-14  0:00                 ` Keith Thompson
1999-05-14  0:00                   ` David C. Hoos, Sr.
1999-05-14  0:00                     ` Keith Thompson
1999-05-15  0:00                       ` David C. Hoos, Sr.
1999-05-16  0:00                   ` Jean-Pierre Rosen
1999-05-13  0:00             ` Marin David Condic [this message]
1999-05-13  0:00               ` Keith Thompson
1999-05-14  0:00                 ` Pascal Obry
1999-05-13  0:00               ` Hyman Rosen
1999-05-15  0:00             ` jrcarter001
1999-06-05  0:00               ` Matthew Heaney
1999-05-12  0:00     ` David C. Hoos, Sr.
1999-05-12  0:00   ` dennison
replies disabled

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