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 JAA04975; Fri, 16 Jul 2004 09:44:47 +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 JAA05778; Fri, 16 Jul 2004 09:44:45 +0200 (MET DST) Received: from lri.lri.fr (lri.lri.fr [129.175.15.1]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6G7iiEV010132; Fri, 16 Jul 2004 09:44:44 +0200 Received: from localhost (localhost [127.0.0.1]) by lri.lri.fr (Postfix) with ESMTP id B0E6119ECA4; Fri, 16 Jul 2004 09:44:44 +0200 (CEST) Received: from lri.lri.fr ([127.0.0.1]) by localhost (lri.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 06799-04; Fri, 16 Jul 2004 09:44:44 +0200 (CEST) Received: from pc8-123 (pc8-123 [129.175.8.123]) by lri.lri.fr (Postfix) with ESMTP id 9425719EC8C; Fri, 16 Jul 2004 09:44:44 +0200 (CEST) Received: from filliatr by pc8-123 with local (Exim 3.35 #1 (Debian)) id 1BlNOe-0004kE-00; Fri, 16 Jul 2004 09:44:44 +0200 From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <16631.34668.403312.730207@gargle.gargle.HOWL> Date: Fri, 16 Jul 2004 09:44:44 +0200 To: henri dubois-ferriere Cc: Pierre Weis , "Basile Starynkevitch [local]" , caml-list@inria.fr Subject: Re: [Caml-list] kprintf with user formatters In-Reply-To: References: <20040715142214.GB28587@bourg.inria.fr> <200407160647.IAA02290@pauillac.inria.fr> <16631.32784.526557.747099@gargle.gargle.HOWL> X-Mailer: VM 7.03 under Emacs 20.7.2 Reply-To: Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre) X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at nez-perce with ID 40F7876C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; filliatre:01 filliatre:01 lri:01 caml-list:01 kprintf:01 formatters:01 lri:01 2004:99 pierre:01 weis:01 runtime:01 discarding:01 ideally:01 printf:01 thunk:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk henri dubois-ferriere writes: > this sounds interesting! could you point us to any available code > showing more of this in practice? Sure: http://why.lri.fr/ (this is a software verification tool) You'll find many instances of the trick I was describing in src/main.ml -- Jean-Christophe Filliātre henri dubois-ferriere writes: > On Fri, 16 Jul 2004 09:13:20 +0200, Jean-Christophe Filliatre > wrote: > > > > Pierre Weis writes: > > > > > > If I understand properly: > > > > > > - you want to skip the runtime time penalty of formatting the > > > arguments to string before discarding the result, > > > - you even want not to parse the format string, > > > - ideally you also want NOT TO EVALUATE the reminding arguments of > > > your printf call ? > > > > > > Hmm, this sounds extremely lazy to me; so this suggests thunk > > > programming; hey, we have that in the language, so let's go! > > > > > > let log level thunk = > > > if may_log level then thunk ();; > > > > > > ... > > > > > > log 2 (fun () -> > > > eprintf "Argument 1 is hard to compute %d\n" (ackermann x x)) > > > > I also use the same kind of trick in practice, with a little > > refinement to avoid building the closure. I introduce higher-order > > functions such as > > > > val if_debug : ('a -> unit) -> 'a -> unit > > > > which behaves like application when the debug flag is on (and does > > nothing otherwise). Then you can simply write > > > > ... > > if_debug eprintf "this is a message"; > > ... > > > > I even introduce variants for functions with more than one argument to > > be able to write stuff like > > > > ... > > if_debug3 eprintf "syntax tree is %a@." print_tree t; > > ... > > > > without addition of parentheses. I still find this very convenient and > > not obtrusive as far as style is concerned. > > > > Hope this helps, > > -- > > Jean-Christophe Filliātre (http://www.lri.fr/~filliatr) > > > > > > > > ------------------- > > 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 > > ------------------- 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