From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=AWL,MAILTO_TO_SPAM_ADDR, SPF_FAIL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 4ABA0BC6B for ; Tue, 6 Nov 2007 18:14:35 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPIvMEfAXQImh2dsb2JhbACOfgEICik X-IronPort-AV: E=Sophos;i="4.21,379,1188770400"; d="scan'208";a="19002514" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 06 Nov 2007 18:14:34 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lA6HEF8H002280 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 6 Nov 2007 18:14:34 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPIvMEdQW+UCh2dsb2JhbACOfgEICik X-IronPort-AV: E=Sophos;i="4.21,379,1188770400"; d="scan'208";a="19002506" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail4-smtp-sop.national.inria.fr with ESMTP; 06 Nov 2007 18:14:33 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IpRsw-0005aU-Sr for caml-list@inria.fr; Tue, 06 Nov 2007 17:06:42 +0000 Received: from ks300734.kimsufi.com ([91.121.65.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Nov 2007 17:06:42 +0000 Received: from sylvain by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Nov 2007 17:06:42 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: log function without evaluate arguments Date: Tue, 6 Nov 2007 16:57:54 +0000 (UTC) Message-ID: References: <47309EEC.4080706@menta.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com User-Agent: slrn/0.9.8.1pl2 (Debian) Sender: news X-Miltered: at discorde with ID 4730A0E7.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; le-gall:01 kprintf:01 camlp:01 syntax:01 val:01 printf:01 printf:01 sugestions:01 syntax:01 val:01 2007,:98 callers:98 wrote:01 minor:01 boolean:01 On 06-11-2007, tmp123 wrote: > Hello, > > In order to implement a function that prints log messages only, by > example, if a boolean flag is true, and does nothing elsewhere, I've > been reading the (long) post sequence "kprintf with user formatters" > (2004 Jun 30). > > In this context, "does nothing" means not convert parameters to text nor > evaluate them. > > If my understanting of the reading has been correct, one of the best > options seems to be something like (in camlp4r revised syntax, I'm more > used to it): > > value log_flag = ref False; > > value log e = > if log_flag.val > then > Lazy.force e > else (); > > and the callers must include lines like: > > log (lazy (Printf.printf "%d" (sum 1 3))); > > Please, is this a good way? Some sugestions to made it better in > performance or syntax? > > Thanks a lot. > I am used to : value log e = if log_flag.val then e () else (); avec log (fun () -> (Printf.printf "%d" (sum 1 3))) But the enhancement is minor. Regards, Sylvain Le Gall