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 JAA04867; Fri, 16 Jul 2004 09:23:13 +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 JAA04540 for ; Fri, 16 Jul 2004 09:23:12 +0200 (MET DST) Received: from mproxy.gmail.com (mproxy.gmail.com [216.239.56.246]) by concorde.inria.fr (8.12.10/8.12.10) with SMTP id i6G7NASH020479 for ; Fri, 16 Jul 2004 09:23:10 +0200 Received: by mproxy.gmail.com with SMTP id w29so1820987cwb for ; Fri, 16 Jul 2004 00:23:09 -0700 (PDT) Received: by 10.11.116.34 with SMTP id o34mr82361cwc; Fri, 16 Jul 2004 00:23:09 -0700 (PDT) Message-ID: Date: Fri, 16 Jul 2004 00:23:09 -0700 From: henri dubois-ferriere To: Jean-Christophe Filliatre Subject: Re: [Caml-list] kprintf with user formatters Cc: Pierre Weis , "Basile Starynkevitch [local]" , caml-list@inria.fr In-Reply-To: <16631.32784.526557.747099@gargle.gargle.HOWL> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable References: <20040715142214.GB28587@bourg.inria.fr> <200407160647.IAA02290@pauillac.inria.fr> <16631.32784.526557.747099@gargle.gargle.HOWL> X-Miltered: at concorde with ID 40F7825E.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; henridf:01 caml-list:01 kprintf:01 formatters:01 2004:99 filliatre:01 filliatre:01 lri:01 pierre:01 weis:01 runtime:01 discarding:01 ideally:01 printf:01 thunk:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk this sounds interesting! could you point us to any available code showing more of this in practice? thanks henri On Fri, 16 Jul 2004 09:13:20 +0200, Jean-Christophe Filliatre wrote: >=20 > 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 =3D > > if may_log level then thunk ();; > > > > ... > > > > log 2 (fun () -> > > eprintf "Argument 1 is hard to compute %d\n" (ackermann x x)) >=20 > 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 >=20 > val if_debug : ('a -> unit) -> 'a -> unit >=20 > which behaves like application when the debug flag is on (and does > nothing otherwise). Then you can simply write >=20 > ... > if_debug eprintf "this is a message"; > ... >=20 > I even introduce variants for functions with more than one argument to > be able to write stuff like >=20 > ... > if_debug3 eprintf "syntax tree is %a@." print_tree t; > ... >=20 > without addition of parentheses. I still find this very convenient and > not obtrusive as far as style is concerned. >=20 > Hope this helps, > -- > Jean-Christophe Filli=E2tre (http://www.lri.fr/~filliatr) >=20 >=20 >=20 > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inr= ia.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