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-Thread: 103376,64d33c985c8959f0,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.0.170 with SMTP id 10mr6780870pbf.2.1320310414963; Thu, 03 Nov 2011 01:53:34 -0700 (PDT) Path: p6ni65808pbn.0!nntp.google.com!news1.google.com!postnews.google.com!z22g2000prd.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: How does Ada.Text_IO.Enumeration_IO work? Date: Thu, 3 Nov 2011 01:52:35 -0700 (PDT) Organization: http://groups.google.com Message-ID: <865d6298-5a0b-45c5-b0fc-372d6222752f@z22g2000prd.googlegroups.com> NNTP-Posting-Host: 97.117.196.229 Mime-Version: 1.0 X-Trace: posting.google.com 1320310414 7724 127.0.0.1 (3 Nov 2011 08:53:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 3 Nov 2011 08:53:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z22g2000prd.googlegroups.com; posting-host=97.117.196.229; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HLUARECNK X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4,gzip(gfe) Xref: news1.google.com comp.lang.ada:18796 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-03T01:52:35-07:00 List-Id: I don't understand how the following program works, specifically, how instances of Ada.Text_IO.Enumeration_IO read input. I understand that it will skip leading white space, leave anything after finding a proper element including line terminator, that apostophe ' is a valid character, and that it can raise an exception (quoting ARM): "The exception Data_Error is propagated if the sequence input does not have the required syntax, or if the identifier or character literal does not correspond to a value of the subtype Enum." I want the program to read input until a valid element is found, then quit. with Ada.Text_IO; use Ada.Text_IO; with Ada.IO_Exceptions; use Ada.IO_Exceptions; procedure Day_Proc is type Day_Type is (Sunday, Monday, Tuesday); Day : Day_Type; package Day_Type_IO is new Ada.Text_IO.Enumeration_IO(Day_Type); Have_Good_Value : Boolean; begin Put("Enter a day: "); loop Have_Good_Value := True; begin Day_Type_IO.Get(Day); --Skip_Line; -- Doesn't matter if present or not. exception when Ada.IO_Exceptions.Data_Error => Have_Good_Value := False; Put_Line("Exception raised"); end; Put_Line(Boolean'image(Have_Good_Value)); exit when Have_Good_Value; end loop; Put_Line("Your day is " & Day_Type'image(Day)); end Day_Proc; This works as I expect for inputs such as Monday Monday Friday Friday Monday Fri7day Monday Friday ' Monday Monday. etc. but anytime the input contains a non-apostrophe punctuation mark before a valid element, or an otherwise inproperly syntaxed element, it loops endlessly, outputting Exception raised and FALSE for each passage through the loop. For instance, these lines cause infinite looping: Friday. Monday Friday.Monday Friday ? Monday Fri?day Monday Friday 7Thursday Monday This is (or is not) a comment etc. It is correctly raising the exception upon encountering the bad input, but why does it keep looping and not proceed past the bad input to find the following correct element? Jerry