comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de>
Subject: Re: Data_Error and Enumeration_IO
Date: Fri, 13 Jan 2012 00:28:12 +0100
Date: 2012-01-13T00:28:10+01:00	[thread overview]
Message-ID: <4f0f6c8a$0$6637$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <3f3d626a-1b8c-49af-aa85-9e586029a817@z12g2000yqm.googlegroups.com>

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)





  parent reply	other threads:[~2012-01-12 23:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-12 22:41 Data_Error and Enumeration_IO John McCormick
2012-01-12 23:02 ` Jeffrey Carter
2012-01-12 23:28 ` Georg Bauhaus [this message]
2012-01-13  0:10 ` Randy Brukardt
2012-01-13  8:33   ` Dmitry A. Kazakov
2012-01-13 21:30   ` John McCormick
2012-01-13 22:00     ` Jeffrey Carter
2012-01-14  0:09       ` Randy Brukardt
2012-01-14  9:51         ` Dmitry A. Kazakov
2012-01-14 12:25         ` Niklas Holsti
replies disabled

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