Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] kprintf with user formatters
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] kprintf with user formatters

David MENTRE writes:
 >
 > > If the given log level "level" does not allow logging the message
 > > specified by "fmt", I just want to ignore the parameters provided together
 > > with "fmt" - but how?
 > 
 > # let cur_level = ref 0;;
 > val cur_level : int ref = {contents = 0}
 > # let log level fmt =
 >   let print_at_level str = if !cur_level >= level then print_string str in
 >   Format.kprintf print_at_level fmt;;
 > val log : int -> ('a, unit, string, unit) format4 -> 'a = <fun>

This solution still has the drawback of evaluating the whole message
(which can be costly). 

Damien Pous's post has the expected behavior (printf arguments are
simply discarded without any evaluation) but requires Obj.magic...

-- 
Jean-Christophe

-------------------
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