[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Gerd Stolpmann <info@g...> |
| Subject: | Re: [Caml-list] Format question |
Am 2002.11.07 01:09 schrieb(en) Oleg:
> Oleg wrote:
>
> >
> > Is it possible to define a printf that automatically flushes stdout?
> >
>
> I figured it out:
>
> let my_printf (x : ('a, out_channel, unit) format) =
> let tmp = Printf.printf x in flush stdout; tmp;;
No that does not work, output is flushed before anything is printed,
at least if the format string requires an argument. E.g.
# my_printf "%d" 6; prerr_endline "a";;
a
6- : unit = ()
(prerr_endline implies flushing stderr.) In this example, tmp has
type int->unit, and the 6 is applied to tmp after flushing has
been done.
You need kprintf:
let my_printf = Printf.kprintf (fun s -> print_string s; flush stdout; s);;
Unfortunately, my_printf results always in a string. This can't be changed
in O'Caml 3.06, but I have recently seen that there is an improved
kprintf in CVS.
Gerd
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
------------------------------------------------------------
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners