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: Basile Starynkevitch [local] <basile.starynkevitch@i...>
Subject: Re: [Caml-list] kprintf with user formatters
On Thu, Jul 15, 2004 at 03:45:30PM +0200, Markus Mottl wrote:
> On Thu, 15 Jul 2004, Basile Starynkevitch [local] wrote:
> > I don't understand what this zprintf function should be,
> 
> It should parse the format string, and ignore format arguments following
> it.

let zprintf fmt = Printf.kprintf (fun _ -> ()) fmt
should be ok.

But I think that the format string should not even be parsed. I've got
no solution (except the one below) to this!

> 
> I don't think that this hack will be too dangerous.  You might get an
> exception 'Invalid_argument "equal: functional value"' if you want to
> compare those fancy unit-values, which is about the worst thing you
> can achieve.  But who would want to compare unit-values anyway?
> 
> > For what it's worth, long time ago, I ended writing a camlp4 extension
> > for a similar logging (or tracing purpose) see file README.trace and
> > pa_trace.ml of
> > http://cvs.sourceforge.net/viewcvs.py/poesia/PoesiaSoft/PoesiaMonIcap/
> 
> The preprocessor is not good enough for me.  I would like to change
> log levels at runtime, because the application is a server which should
> run permanently.

The above hack was written with the same requirements, and provide the
possibility to change log levels (or log flags actually).

Actually, I more and more hate printf, both in C and in Ocaml. I
really believe it is a nightmare.

A possible suggestion might be to 
  add a StopPrintf exception to Printf
and
  add a tryprintf function to Printf, which takes a prologue function
as an argument. If the prologue raises an exception, no formatting
occur;  otherwise, tryprintf works like kprintf

-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359
http://cristal.inria.fr/~starynke --- all opinions are only mine 

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