caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] flushing stdout with flush stdout not good?
@ 2001-09-03 19:27 Michael Leary
  2001-09-03 20:02 ` Markus Mottl
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Leary @ 2001-09-03 19:27 UTC (permalink / raw)
  To: caml

I'm programming a realtime bot (as you may know :) and using printf with a
newline terminated format string followed by a call of fse ( short for
"flush stdout" in my prog) really doesn't work very well at flushing
stdout -- commands don't get read properly by the system, and get processed
in chunks, rather than as sent.  For some reason calling print_newline is
amazingly more effective, i.e. leaving the newline out of the printf format
string, and letting print_newline () take care of it.

Is this a known feature, or does it have to do with the indirect call of
flush stdout?

-- 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] flushing stdout with flush stdout not good?
  2001-09-03 19:27 [Caml-list] flushing stdout with flush stdout not good? Michael Leary
@ 2001-09-03 20:02 ` Markus Mottl
  2001-09-04  1:59   ` Michael Leary
  0 siblings, 1 reply; 7+ messages in thread
From: Markus Mottl @ 2001-09-03 20:02 UTC (permalink / raw)
  To: Michael Leary; +Cc: caml

On Mon, 03 Sep 2001, Michael Leary wrote:
> I'm programming a realtime bot (as you may know :) and using printf
> with a newline terminated format string followed by a call of fse (
> short for "flush stdout" in my prog) really doesn't work very well at
> flushing stdout -- commands don't get read properly by the system,
> and get processed in chunks, rather than as sent.  For some reason
> calling print_newline is amazingly more effective, i.e. leaving the
> newline out of the printf format string, and letting print_newline ()
> take care of it.

I guess you are using the Format-module, not the Printf-module. The
latter works directly on the stdout buffer, whereas the first maintains a
"pretty-printing buffer" where it can break lines as required.

You can use "print_flush" or "@?" within the format string to flush
things. But be careful: the latter closes all open pretty-printing boxes
as is logically necessary for this operation so better do this only when
all boxes are closed anyway (or you are sure that you want to have them
all closed).

If you don't need automatic line-breaking functionality, the
"Printf"-module is just fine.

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] flushing stdout with flush stdout not good?
  2001-09-03 20:02 ` Markus Mottl
@ 2001-09-04  1:59   ` Michael Leary
  2001-09-04  2:31     ` Michael Leary
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Leary @ 2001-09-04  1:59 UTC (permalink / raw)
  To: Markus Mottl; +Cc: caml

No, as far as I know I'm only using Printf and the print_newline from the
core library...

On Mon, Sep 03, 2001 at 10:02:08PM +0200, Markus Mottl wrote:
> I guess you are using the Format-module, not the Printf-module. The
> latter works directly on the stdout buffer, whereas the first maintains a
> "pretty-printing buffer" where it can break lines as required.

-- 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] flushing stdout with flush stdout not good?
  2001-09-04  1:59   ` Michael Leary
@ 2001-09-04  2:31     ` Michael Leary
  2001-09-04  2:40       ` Alexander V. Voinov
  2001-09-04  2:53       ` Jon Moore
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Leary @ 2001-09-04  2:31 UTC (permalink / raw)
  To: Markus Mottl; +Cc: caml

I should give example:

a series of about 13 functions like these:

let name s = printf "Name %s" s; print_newline ()
let color c = printf "Colour %s" c; print_newline ()

about half have three or four arguments, usually floats

if I write them this way:

let fso = flush stdout
let name s = printf "Name %s\n" s; fso
let color c = printf "Colour %s\n" c; fso

It becomes very ugly and "bursty".  The only modules in use are Str,
Printf, and List.

-- 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] flushing stdout with flush stdout not good?
  2001-09-04  2:31     ` Michael Leary
@ 2001-09-04  2:40       ` Alexander V. Voinov
  2001-09-04  2:53       ` Jon Moore
  1 sibling, 0 replies; 7+ messages in thread
From: Alexander V. Voinov @ 2001-09-04  2:40 UTC (permalink / raw)
  To: Michael Leary; +Cc: Markus Mottl, caml

Hi All,

Michael Leary wrote:
> let fso = flush stdout
> let name s = printf "Name %s\n" s; fso
> let color c = printf "Colour %s\n" c; fso

A question to All concerned, especially to the language creators. As I
understood the notion of 'eagerness', the first line should evaluate
immediately (, flush stdout) and return () (or whatever does 'flush'
return). In the subsequent functions this value would be reevaluated to
itself, returned and discarded. No more flushes to stdout should appear
at these. Right? Is there just a misprint, so that the correct
definition should read:

let fso () = flush stdout?

Alexander
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] flushing stdout with flush stdout not good?
  2001-09-04  2:31     ` Michael Leary
  2001-09-04  2:40       ` Alexander V. Voinov
@ 2001-09-04  2:53       ` Jon Moore
  2001-09-04 17:55         ` Michael Leary
  1 sibling, 1 reply; 7+ messages in thread
From: Jon Moore @ 2001-09-04  2:53 UTC (permalink / raw)
  To: Michael Leary; +Cc: caml-list

> if I write them this way:
> 
> let fso = flush stdout
> let name s = printf "Name %s\n" s; fso
> let color c = printf "Colour %s\n" c; fso

I think what you mean to write here is:

let fso () = flush stdout
let name s = printf "Name %s\n" s; fso ()
let color c = printf "Colour %s\n" c; fso ()

In the code you wrote above, "fso" gets bound to () (and not to a function)
after flushing stdout once. So the name and color functions you wrote are
doing prints, and returning units, rather than invoking the flush as you
thought. Thus, this is why the output becomes bursty (you're not actually
flushing).

Jon
..........
Jonathan Moore                              http://www.cis.upenn.edu/~jonm
University of Pennsylvania                          jonm@dsl.cis.upenn.edu
'Frater qui adiuvatur a fratre quasi civitas firma.' (Brother helped by
brother is a fortress).
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] flushing stdout with flush stdout not good?
  2001-09-04  2:53       ` Jon Moore
@ 2001-09-04 17:55         ` Michael Leary
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Leary @ 2001-09-04 17:55 UTC (permalink / raw)
  To: Jon Moore; +Cc: caml-list

On Mon, Sep 03, 2001 at 10:53:56PM -0400, Jon Moore wrote:
> In the code you wrote above, "fso" gets bound to () (and not to a function)
> after flushing stdout once. So the name and color functions you wrote are
> doing prints, and returning units, rather than invoking the flush as you
> thought. Thus, this is why the output becomes bursty (you're not actually
> flushing).

Heh, a pretty obvious mistake now that I look at it...  If it's fully
applied it's only the return value, otherwise it's a partially applied
function/closure awaiting more args.  All that lambda calculus stuff. :)

-- 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-09-04 17:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-03 19:27 [Caml-list] flushing stdout with flush stdout not good? Michael Leary
2001-09-03 20:02 ` Markus Mottl
2001-09-04  1:59   ` Michael Leary
2001-09-04  2:31     ` Michael Leary
2001-09-04  2:40       ` Alexander V. Voinov
2001-09-04  2:53       ` Jon Moore
2001-09-04 17:55         ` Michael Leary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).