English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
log function without evaluate arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-06 (16:11)
From: tmp123 <tmp123@m...>
Subject: log function without evaluate arguments
Hello,

In order to implement a function that prints log messages only, by
example, if a boolean flag is true, and does nothing elsewhere, I've
been reading the (long) post sequence "kprintf with user formatters"
(2004 Jun 30).

In this context, "does nothing" means not convert parameters to text nor
evaluate them.

If my understanting of the reading has been correct, one of the best
options seems to be something like (in camlp4r revised syntax, I'm more
used to it):

value log_flag = ref False;

value log e =
  if log_flag.val
  then
    Lazy.force e
  else ();

and the callers must include lines like:

log (lazy (Printf.printf "%d" (sum 1 3)));

Please, is this a good way? Some sugestions to made it better in
performance or syntax?

Thanks a lot.