Browse thread
[Caml-list] kprintf with user formatters
[
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-15 (07:42) |
From: | Damien <Damien.Pous@e...> |
Subject: | Re: [Caml-list] kprintf with user formatters |
On Thu, 15 Jul 2004 02:17:58 +0200 Markus Mottl wrote: > Btw., since we are at it: I'd like to use my own printers depending on > a conditional, e.g.: > > let log level fmt = > if may_log level then > kfprintf ... > else > ??? > > 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? Is there some (safe) trick, or do I > have to write my own Printf/Format-modules? I don't want to waste > computation time by unnecessarily converting format arguments to > strings, which may be very costly, e.g. when this would mean > converting IPs to hostnames, etc. I had the same problem a month ago, I ended with the following ugly function: let log b fmt = if b then Printf.printf fmt else let rec f x = Obj.magic f in f fmt (* val f: bool -> ('a, out_channel, unit) format -> 'a *) (I think this is safe since f just eats its arguments, and gets typed with "-rectypes" : ('b->'a) as 'a) maybe a function "zprintf" could be added to Printf and Format to do this job ? regards, damien ------------------- 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