caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Oleg <oleg_inconnu@myrealbox.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Format question
Date: Thu, 7 Nov 2002 01:46:06 +0100	[thread overview]
Message-ID: <20021107004606.GA925@ice.gerd-stolpmann.de> (raw)
In-Reply-To: <200211070009.TAA00453@apakabar.cc.columbia.edu>; from oleg_inconnu@myrealbox.com on Don, Nov 07, 2002 at 01:09:23 +0100


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


  parent reply	other threads:[~2002-11-07  0:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-07  0:09 Oleg
2002-11-07  0:31 ` Alessandro Baretta
2002-11-07  0:46 ` Gerd Stolpmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-11-06 22:49 Oleg
2002-11-06 23:46 ` David Brown
2002-11-20  0:29 ` David Frese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021107004606.GA925@ice.gerd-stolpmann.de \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@inria.fr \
    --cc=oleg_inconnu@myrealbox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).