From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,386228a37afe967f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-18 11:17:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.aset.psu.edu!not-for-mail From: Robert Spooner Newsgroups: comp.lang.ada Subject: Re: Computer Language Shootout Date: Fri, 18 Jul 2003 14:04:41 -0400 Organization: Penn State University, Center for Academic Computing Message-ID: References: <1ec946d1.0307150715.4ba69f85@posting.google.com> <3F149243.80304@attbi.com> <3F15930C.2070907@attbi.com> NNTP-Posting-Host: nat1.arl.psu.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: f04n12.cac.psu.edu 1058551481 41840 128.118.40.100 (18 Jul 2003 18:04:41 GMT) X-Complaints-To: usenet@f04n12.cac.psu.edu NNTP-Posting-Date: Fri, 18 Jul 2003 18:04:41 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en,de,fr-FR In-Reply-To: Xref: archiver1.google.com comp.lang.ada:40481 Date: 2003-07-18T14:04:41-04:00 List-Id: Robert A Duff wrote: > "Jean-Pierre Rosen" writes: > > >>This one reads a line with no length limit: >> >>function Get_Line return String is >> Buffer : String (1..500); -- or whatever >> Last : Natural; >>begin >> Get_Line (Buffer, Last); >> if Last < Buffer'Last then >> return Buffer (1..Last); >> else >> return Buffer & Get_Line; >> end if; >>end Get_Line; >> >>In most cases, there will be only one call, while having no upper limit. >>The size of the buffer is just a matter of optimization. > > > This is a nice trick, but I suggest you grow the buffer exponentially, > in case lines are very long. Like, double it on each recursion level. > > Too bad this was not included in Text_IO itself. It would save > beginners a lot of trouble. Sigh. > > - Bob I tried this using the following program and gnat version 3.13p on windows professional 2000 with the following result: with Ada.Text_IO; procedure No_String_Length_Limit_Test is package Tio renames Ada.Text_IO; function Get_Line (Buffer_Size : Positive := 1) return String is Buffer : String (1..Buffer_Size); Last : Natural; begin Tio.Get_Line (Buffer, Last); if Last < Buffer'Last then return Buffer(1..Last); else return Buffer & Get_Line (2*Buffer_Size); end if; end Get_Line; begin -- No_String_Length_Limit_Test loop Tio.Put ("Enter a message, to exit: "); declare The_Message : String := Get_Line; begin exit when The_Message'Length = 0; Tio.Put_Line ("The message is " & The_Message); end; end loop; end No_String_Length_Limit_Test; no_string_length_limit_test.adb:16:26: ambiguous operand for concatenation no_string_length_limit_test.adb:16:26: possible interpretation at line 8 Done--error detected. Can someone tell me why the operand is ambiguous? Bob -- Robert L. Spooner Registered Professional Engineer Associate Research Engineer Intelligent Control Systems Department Applied Research Laboratory Phone: (814) 863-4120 The Pennsylvania State University FAX: (814) 863-7841 P. O. Box 30 State College, PA 16804-0030 rls19@psu.edu