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 BAA03474; Wed, 20 Nov 2002 01:27:23 +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 BAA03323 for ; Wed, 20 Nov 2002 01:27:21 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from localhost.localdomain (p5088E8EC.dip.t-dialin.net [80.136.232.236]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gAK0RLX03076 for ; Wed, 20 Nov 2002 01:27:21 +0100 (MET) Received: by localhost.localdomain (Postfix, from userid 501) id 3D5D41A684F; Tue, 19 Nov 2002 19:29:16 -0500 (EST) Subject: Re: [Caml-list] Format question From: David Frese To: Oleg Cc: Caml-list In-Reply-To: <200211062249.RAA07810@apakabar.cc.columbia.edu> References: <200211062249.RAA07810@apakabar.cc.columbia.edu> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8-3mdk Date: 20 Nov 2002 01:29:16 +0100 Message-Id: <1037752156.2910.10.camel@localhost.localdomain> Mime-Version: 1.0 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 2002-11-06 at 23:49, Oleg wrote: > Hi > > Is it possible to define a printf that automatically flushes stdout? > > let my_printf x = Printf.printf x; flush stdout;; > > my_printf "%i" 3;; > > doesn't work (Incorrect number of arguments, as the type of my_printf is > different from Printf.printf) Hello, I read your message a little late, but this seems to work: let flprintf ch fmt = let rec test x = if (Obj.magic x) = () then begin flush ch; Obj.magic () end else Obj.magic (fun next -> test ((Obj.magic x) next)) in test (Printf.fprintf ch fmt) let my_printf = flprintf stdout As far as I know, no function will ever be represented as 0, which is the internal representation of (). The code depends on that fact... David. ------------------- 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