From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA00926; Thu, 7 Nov 2002 01:46:24 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA01381 for ; Thu, 7 Nov 2002 01:46:22 +0100 (MET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gA70kC525108 for ; Thu, 7 Nov 2002 01:46:16 +0100 (MET) Received: from [212.227.126.160] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 189aoE-00056q-00; Thu, 07 Nov 2002 01:46:10 +0100 Received: from [80.129.99.232] (helo=gate.gerd-stolpmann.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 189aoE-00019t-00; Thu, 07 Nov 2002 01:46:10 +0100 Received: from ice.gerd-stolpmann.de (ice.gerd-stolpmann.de [192.168.0.13]) by gate.gerd-stolpmann.de (Postfix) with ESMTP id AFC69CCDD; Thu, 7 Nov 2002 01:46:08 +0100 (CET) Received: from ice (localhost [127.0.0.1]) by ice.gerd-stolpmann.de (Postfix) with ESMTP id 6C808B0B7; Thu, 7 Nov 2002 01:46:07 +0100 (CET) Date: Thu, 7 Nov 2002 01:46:06 +0100 From: Gerd Stolpmann To: Oleg Cc: caml-list@inria.fr Subject: Re: [Caml-list] Format question Message-ID: <20021107004606.GA925@ice.gerd-stolpmann.de> References: <200211070009.TAA00453@apakabar.cc.columbia.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200211070009.TAA00453@apakabar.cc.columbia.edu>; from oleg_inconnu@myrealbox.com on Don, Nov 07, 2002 at 01:09:23 +0100 X-Mailer: Balsa 1.4.1 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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