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 JAA11272; Thu, 15 Jul 2004 09:42:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA11985 for ; Thu, 15 Jul 2004 09:42:10 +0200 (MET DST) Received: from fafnir.ens-lsh.fr (fafnir.ens-lsh.fr [193.51.131.254]) by nez-perce.inria.fr (8.12.10/8.12.10) with SMTP id i6F7g9EV023402 for ; Thu, 15 Jul 2004 09:42:09 +0200 Received: from ([172.16.1.1]) by fafnir.ens-lsh.fr; Thu, 15 Jul 2004 09:42:14 +0200 (CEST) Received: from avalon.ens-lsh.fr (localhost [127.0.0.1]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id i6F8eX9R021380 for ; Thu, 15 Jul 2004 09:40:33 +0100 (WEST) Received: from ens-notes1.ens-lsh.fr (ens-notes1.ens-lsh.fr [10.2.1.44]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id i6F8eW5w021377 for ; Thu, 15 Jul 2004 09:40:32 +0100 (WEST) Received: from mostha ([10.3.25.139]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2004071509420486:9116 ; Thu, 15 Jul 2004 09:42:04 +0200 Date: Thu, 15 Jul 2004 09:39:53 +0200 From: Damien To: caml-list@inria.fr Subject: Re: [Caml-list] kprintf with user formatters Message-Id: <20040715093953.53769963@mostha> In-Reply-To: <20040715001758.GF26614@fichte.ai.univie.ac.at> References: <20040630183237.457317c7@mostha> <200407142110.XAA25344@pauillac.inria.fr> <20040715001758.GF26614@fichte.ai.univie.ac.at> Organization: mosthagloups X-Mailer: Sylpheed version 0.9.11claws (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 15/07/2004 09:42:04, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 15/07/2004 09:42:06, Serialize complete at 15/07/2004 09:42:06 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Miltered: at nez-perce with ID 40F63551.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; damien:01 damien:01 ens-lyon:01 caml-list:01 kprintf:01 formatters:01 2004:99 fmt:01 fmt:01 printf:01 ips:99 printf:01 val:01 eats:01 -rectypes:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 15 Jul 2004 02:17:58 +0200 Markus Mottl wrote: > Btw., since we are at it: I'd like to use my own printers depending on > a conditional, e.g.: > > let log level fmt = > if may_log level then > kfprintf ... > else > ??? > > If the given log level "level" does not allow logging the message > specified by "fmt", I just want to ignore the parameters provided > together with "fmt" - but how? Is there some (safe) trick, or do I > have to write my own Printf/Format-modules? I don't want to waste > computation time by unnecessarily converting format arguments to > strings, which may be very costly, e.g. when this would mean > converting IPs to hostnames, etc. I had the same problem a month ago, I ended with the following ugly function: let log b fmt = if b then Printf.printf fmt else let rec f x = Obj.magic f in f fmt (* val f: bool -> ('a, out_channel, unit) format -> 'a *) (I think this is safe since f just eats its arguments, and gets typed with "-rectypes" : ('b->'a) as 'a) maybe a function "zprintf" could be added to Printf and Format to do this job ? regards, damien ------------------- 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