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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5c3042563529d4f3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,CP1252 Received: by 10.68.196.130 with SMTP id im2mr204188pbc.3.1326410891000; Thu, 12 Jan 2012 15:28:11 -0800 (PST) Path: lh20ni175390pbb.0!nntp.google.com!news1.google.com!goblin2!goblin.stu.neva.ru!feeder2.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 13 Jan 2012 00:28:12 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; en-US; rv:1.9.2.25) Gecko/20111213 Thunderbird/3.1.17 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Data_Error and Enumeration_IO References: <3f3d626a-1b8c-49af-aa85-9e586029a817@z12g2000yqm.googlegroups.com> In-Reply-To: <3f3d626a-1b8c-49af-aa85-9e586029a817@z12g2000yqm.googlegroups.com> Message-ID: <4f0f6c8a$0$6637$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 13 Jan 2012 00:28:10 CET NNTP-Posting-Host: 79c225ff.newsspool2.arcor-online.net X-Trace: DXC=Z2>>^Tn0]4V=>bdbdS?M0YA9EHlD;3YcR4Fo<]lROoRQ8kFejVXXLBP6Z3;If^E<[76`J:;jU X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-01-13T00:28:10+01:00 List-Id: On 1/12/12 11:41 PM, John McCormick wrote: > However, when my students leave out the call to Skip_Line in the > Data_Error exception handler the behavior depends on the actual value > entered. It still works as desired when the input is alphabetic > characters such as �abc�. But when the input consists of digits such > as �123� the loop becomes infinite, repeating the prompt and error > message. It appears to me that the call to Choice_IO.Get consumes the > alphabetic input but does not consume the digit input leaving it > available for the next call to Get. I could not find anything in the > language reference manual about how Enumeration_IO consumes input > characters when Data_Error is raised. Can anyone give me an > explanation? Is it implementation defined? I am running GNAT GPL > 2011. This scenario looks almost exactly like that of subsection 23.3.8, "Invalid Data", in section 23.3, "Text Input and Output", of [1]. If my understanding is correct. The subsection explains the infinite loop and also suggest Skip_Line. (These books are smarter than I am, which is most helpful, but OTOH this means I might be wrong in applying the text to your example.) The difference is that the book's example uses an instance of Float_IO and its example input text is "123.45E*". "Only those characters conforming to the syntax of the specified type are input. When the call to Get encounters the asterisk, Data_Error is raised since an asterisk does not conform to the syntax of a real number. The asterisk is never input by the call to Get, even though it has been examined by Get. The exception is handled, and "[some message/prompt]" is output. Upon each iteration, Get encounters the same invalid asterisk character, raises Data_Error, and so on ad infinitum. "(...) "In general, the Get routines of the four generic packages in Text_Io begin by skipping preceding blanks, tabs, line, and page terminators. A sequence of characters is then read until the syntax of values of the target type is no longer satisfied or a line terminator is encountered. The character sequence read is then checked to see that it is a syntactically legal value and a value of the target subtype. If either check fails, then Data_Error is raised. "(...) "A third solution is to use only Get_Line. The string read can then be analysed using the Get subprograms that read from strings." "(...) "[Ada83] 14.3.5(1 ..2, 5 .. 6, 10); 14.3..8)8 .. 11, 17 .. 19); 14.4(8)" HTH __ [1] (Author => (1 => "Mendal, Geoffrey O.", 2 => "Bryan, Douglas L."), Year => 1992, Title => "Exploring Ada", Volume => 2, Publisher => "Prentice-Hall, Inc.", ISBN => 0-13-297227-1)