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 TAA31482; Fri, 16 Jul 2004 19:44:56 +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 TAA31520; Fri, 16 Jul 2004 19:44:54 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6GHirEV017772; Fri, 16 Jul 2004 19:44:53 +0200 Received: from fichte.ai.univie.ac.at (markus@localhost [127.0.0.1]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) with ESMTP id i6GHirDu004149; Fri, 16 Jul 2004 19:44:53 +0200 Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) id i6GHirbY004148; Fri, 16 Jul 2004 19:44:53 +0200 Date: Fri, 16 Jul 2004 19:44:53 +0200 From: Markus Mottl To: Pierre Weis Cc: caml-list@inria.fr Subject: Re: [Caml-list] kprintf with user formatters Message-ID: <20040716174453.GD741@fichte.ai.univie.ac.at> Mail-Followup-To: Pierre Weis , caml-list@inria.fr References: <20040715142214.GB28587@bourg.inria.fr> <200407160647.IAA02290@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200407160647.IAA02290@pauillac.inria.fr> User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 40F81415.002 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 pierre:01 weis:01 thunk:01 thunk:01 eprintf:01 ackermann:01 thunks:01 sprintf:01 ocamlp:01 runtime:01 thunks:01 sprintf:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 16 Jul 2004, Pierre Weis wrote: > 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 have used thunks (and lazy values) before, but they are usually syntactically ugly. Instead of: log (fun () -> sprintf "%d" n) I'd rather want to write log "%d" n without having the log function compute a string from an integer if this is not necessary. Would this really be so difficult to support? > That's the way we use to log in the OcamlP3l compiler: we've got no > runtime penalty if there is no necessity to log. Well, you have to create a thunk, but this cost is acceptable to me. I just don't want to clutter my code with thunks + additional sprintf statements. > Moreover, this solution is general enough to accomodate threads, > side effects, or whatever. You always need mutexes if you want to prevent that your output gets messed up by multiple threads. > To me the (fun () -> ) additional verbosity is not so bad: it clearly > emphasizes that nothing at all is evaluated when logging is unnecessary. It's rather the other way round: people using format strings may get the wrong idea that arguments are not converted if there is no output. > To go beyond that, we would need some help from the language that > would offer some provision for debugging from a special debug keyword, > semantically reminiscent to lazy and assert (as a kind of combined > semantics of both constructs). A compiler flag would then > automatically remove the debugging code (as is done for assert with > the -noassert flag) and the compiler will automatically insert the > (fun () -> ) as it already does in the case of lazy ... I don't think it is necessary or even useful to introduce new keywords. A customized, beautiful solution would be possible with camlp4, thunks solve the problem semantically, but look ugly, and some support for a kind of zprintf would be ideal :-) Regards, Markus -- Markus Mottl http://www.oefai.at/~markus markus@oefai.at ------------------- 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