[m-dev.] trivial diff: fix calculator.m bug

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 3 12:24:32 AEDT 1999


On 03-Nov-1999, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> On Fri, Oct 29, 1999 at 04:13:27PM EST, Fergus Henderson wrote:
> > On 29-Oct-1999, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> > > On Thu, Oct 28, 1999 at 07:45:31PM EST, Fergus Henderson wrote:
> > > >  main --> 
> > > > +	io__write_string("calculator> "),
> > > 
> > > Should that have a call to io__flush_output?
> > 
> > Hmmm.  I'm not sure.  It seems to work fine without one.
> > 
> > (If we do add one here, we would also need to add one
> > to samples/interpreter.m and samples/eliza.m and perhaps
> > elsewhere.)
> 
> If it seems to work then well and good. I think it doesn't
> work if the output isn't straight to a tty (eg piped through
> a pager, or tee, etc).

Yes, you're right.  Piping the output through an ordinary pager (e.g. less
or more) doesn't make much sense for these kinds of interactive applications,
since the pager and the application will be fighting for the user's input.
But piping the output into tee makes perfect sense, and the calls to
io__flush_output are needed in that case.

----------

Estimated hours taken: 0.1

samples/calculator.m:
samples/eliza.m:
samples/interpreter.m:
	Add calls to `io__flush_output', so that the input and output
	are interleaved properly when you run the programs with output
	redirected to a pipe, e.g. "./calculator | tee logfile".

Workspace: /home/mercury0/fjh/mercury
Index: samples/calculator.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/calculator.m,v
retrieving revision 1.7
diff -u -d -r1.7 calculator.m
--- calculator.m	1999/10/28 09:45:42	1.7
+++ calculator.m	1999/11/03 01:16:14
@@ -25,6 +25,7 @@
 
 main --> 
 	io__write_string("calculator> "),
+	io__flush_output,
 	io__read_line(Res),
 	( { Res = error(_) },
 		io__write_string("Error reading from stdin\n")
Index: samples/eliza.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/eliza.m,v
retrieving revision 1.12
diff -u -d -r1.12 eliza.m
--- eliza.m	1997/09/12 02:17:13	1.12
+++ eliza.m	1999/11/03 01:17:15
@@ -129,6 +129,7 @@
 :- mode eliza__read_line(out, out, di, uo) is det.
 eliza__read_line(Line, Ok) -->
 	io__write_string("\n> "),
+	io__flush_output,
 	io__input_stream(Stdin),
 	io__read_line(Stdin, Result),
 	io__write_string("\n"),
Index: samples/interpreter.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/interpreter.m,v
retrieving revision 1.4
diff -u -d -r1.4 interpreter.m
--- interpreter.m	1997/09/29 15:25:58	1.4
+++ interpreter.m	1999/11/03 01:16:42
@@ -49,6 +49,7 @@
 
 main_loop(Database) -->
 	io__write_string("?- "),
+	io__flush_output,
 	term_io__read_term(ReadTerm),
 	main_loop_2(ReadTerm, Database).
 
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list