From: Brian Drummond <brian@shapes.demon.co.uk>
Subject: Re: Trouble with loop in Ada
Date: Fri, 4 Jan 2013 10:59:24 +0000 (UTC)
Date: 2013-01-04T10:59:24+00:00 [thread overview]
Message-ID: <kc6cmc$37a$1@dont-email.me> (raw)
In-Reply-To: kc5m0s$tth$1@speranza.aioe.org
On Fri, 04 Jan 2013 04:32:28 +0000, Derek Wyss wrote:
> Hello,
>
> I'm new to Ada and I'm trying to write a toy unix command shell just to
> explore the programming language. So far I have a very small program,
> but I am confused about its behavior.
> Can anyone offer an explanation as to why I need to press enter? I
> suspect it has to do with my use of End_Of_File and the way it "looks
> ahead" but I'm not really sure.
The confusing thing to me is not that you have to press enter, but that
you have to press it twice the first time round.
I started it and pressed ijklmn THEN return...
ijklmn
Enter a character> you entered: i
Enter a character> you entered: j
Enter a character> you entered: k
...
which explains it.
(1) First, End_Of_File must block until there is input. (It has to wait
to see if you are going to type Ctrl-C) And there isn't input until there
is at least one character followed by a return.
(2) Then Get returns one character at a time from the line buffer, until
it runs out, when it blocks again until there is more input.
So the behaviour comes from the library functions behind Get and
End_Of_File rather than the loop. The question is whether you can get
what you want from these, or need to find alternatives.
Now the good news : loops are more flexible in Ada; there are other ways
of using them. So your immediate problem can be solved by:
loop
Put("Enter a character> ");
Get(input_char);
Put("you entered: " & input_char);
New_line;
exit when End_Of_File;
end loop;
Oh and very nicely done on the toy example - that's the way to get help!
- Brian
next prev parent reply other threads:[~2013-01-04 10:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-04 4:32 Trouble with loop in Ada Derek Wyss
2013-01-04 10:59 ` Brian Drummond [this message]
2013-01-04 11:11 ` Brian Drummond
2013-01-04 12:44 ` Paul Colin Gloster
2013-01-04 21:27 ` Derek Wyss
2013-01-05 5:33 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox