comp.lang.ada
 help / color / mirror / Atom feed
From: rieachus@comcast.net
Subject: Re: Why does this input get "skipped"?
Date: Sat, 20 Aug 2016 17:00:13 -0700 (PDT)
Date: 2016-08-20T17:00:13-07:00	[thread overview]
Message-ID: <d5fe6649-5c66-4e75-9888-c93641a36a41@googlegroups.com> (raw)
In-Reply-To: <07632b3f-f419-4865-a8f8-01b568a6883e@googlegroups.com>

On Saturday, August 20, 2016 at 6:41:57 PM UTC-4, John Smith wrote:
> This is the snippet in question:
> Ada.Text_IO.Put("Delete a value - > ");
> String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
> Ada.Text_IO.New_Line;
> 
> The purpose is to have the user enter some string and then keep going.  When I ran the above code, I found that I saw "Delete a value - > " being printed, but the program didn't even give me a chance to enter some form of text...
> 
> Why did my code keep running?

There are two possibilities I see.  The first is that you expect that there is no input waiting when you output "Delete a value ->"  The call to Put will not erase any waiting input.  If there is a line waiting, in particular if End_Of_Line is true, you will get input.  If EOL is not true, and there is no EOL or EOP in the in the input buffer, it should wait.  But...  You next execute  New_Line.  If Current_Input and Current_Output are different files, no problem.  But there is no explicit barrier between the two calls, and any decent implementation of Text_IO will allow for task switches when waiting for input.  Looking at the New_Line is a bug, but I don't imagine there are any tests for it.  Consuming it would be wrong, but looking at the input and seeing a previous EOL is correct.

If you write your code:

Ada.Text_IO.Put_Line("Delete a value - > ");
String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
Ada.Text_IO.New_Line;

You should get what you want.  When working with a screen, I would not use Text_IO which was really designed for a terminal consisting of a keyboard and printer.  With Text_IO though, two good rules are: 1) A sequence of Puts should always end with a Put_Line or New_Line. 2) For input files, read input a line at a time into a String, then read from that String. Again, if you need to do other than line at a time I/O, you shouldn't beusing Text_IO.

(Confession: I wrote several Lisp drivers for specific display terminals on Multics.  When I needed to use display terminals with Ada, I knew enough to be able to treat them as full screen character displays.  Every time I thought I should create a clean Ada package instead of kludging Text_IO, but I never did.)

      parent reply	other threads:[~2016-08-21  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-20 22:41 Why does this input get "skipped"? John Smith
2016-08-20 23:16 ` Jeffrey R. Carter
2016-08-21  0:01   ` John Smith
2016-08-21  0:36     ` John Smith
2016-08-22  5:00       ` J-P. Rosen
2016-08-22 22:18       ` rieachus
2016-08-23  6:22         ` J-P. Rosen
2016-08-24 10:34           ` rieachus
2016-08-21  0:50     ` Jeffrey R. Carter
2016-08-21  1:04       ` John Smith
2016-08-21  4:07         ` Jeffrey R. Carter
2016-08-21  0:00 ` rieachus [this message]
replies disabled

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