Browse thread
[Caml-list] kprintf with user formatters
-
Damien
-
Pierre Weis
-
Markus Mottl
- David MENTRE
- Damien
- Pierre Weis
- james woodyatt
-
Markus Mottl
-
Pierre Weis
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2004-07-16 (07:44) |
From: | Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...> |
Subject: | Re: [Caml-list] kprintf with user formatters |
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 > <jean-christophe.filliatre@lri.fr> 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