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 JAA11768; Thu, 15 Jul 2004 09:30:56 +0200 (MET DST) 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 JAA10629 for ; Thu, 15 Jul 2004 09:30:55 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mwinf0301.wanadoo.fr (smtp3.wanadoo.fr [193.252.22.28]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6F7UsSH014517 for ; Thu, 15 Jul 2004 09:30:54 +0200 Received: from morgana (ARennes-303-1-11-41.w81-49.abo.wanadoo.fr [81.49.36.41]) by mwinf0301.wanadoo.fr (SMTP Server) with ESMTP id 674E8400720 for ; Thu, 15 Jul 2004 09:30:54 +0200 (CEST) Received: from david by morgana with local (Exim 4.32) id 1Bl0hh-0000Q7-GZ for caml-list@inria.fr; Thu, 15 Jul 2004 09:30:53 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] kprintf with user formatters References: <20040630183237.457317c7@mostha> <200407142110.XAA25344@pauillac.inria.fr> <20040715001758.GF26614@fichte.ai.univie.ac.at> From: David MENTRE Organization: none Date: Thu, 15 Jul 2004 09:30:53 +0200 In-Reply-To: <20040715001758.GF26614@fichte.ai.univie.ac.at> (Markus Mottl's message of "Thu, 15 Jul 2004 02:17:58 +0200") Message-ID: <87fz7tybf6.fsf@linux-france.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 40F632AE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 kprintf:01 formatters:01 dmentre:01 fmt:01 fmt:01 val:01 kprintf:01 val:01 toto:01 toto:01 damien:01 dmentre:01 caml:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, Markus Mottl writes: > 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? # let cur_level = ref 0;; val cur_level : int ref = {contents = 0} # let log level fmt = let print_at_level str = if !cur_level >= level then print_string str in Format.kprintf print_at_level fmt;; val log : int -> ('a, unit, string, unit) format4 -> 'a = # log 3 "%d %s" 3 "toto";; - : unit = () # cur_level := 4;; - : unit = () # log 3 "%d %s" 3 "toto";; 3 toto- : unit = () The trick is to call kprintf as last expression. Thank you to Damien Doligez: http://caml.inria.fr/archives/200405/msg00355.html I hope it helps, Yours, d. -- David Mentré ------------------- 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