caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* log function without evaluate arguments
@ 2007-11-06 17:05 tmp123
  2007-11-06 16:57 ` Sylvain Le Gall
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: tmp123 @ 2007-11-06 17:05 UTC (permalink / raw)
  To: caml-list

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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-11-07 13:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-06 17:05 log function without evaluate arguments tmp123
2007-11-06 16:57 ` Sylvain Le Gall
2007-11-06 18:25 ` [Caml-list] " Nicolas Pouillard
2007-11-06 18:40   ` Till Varoquaux
2007-11-06 18:49     ` Brian Hurt
2007-11-07  3:39       ` Christopher L Conway
2007-11-07  4:00         ` Erik de Castro Lopo
2007-11-07  4:10           ` Christopher L Conway
2007-11-07 13:42             ` Brian Hurt
2007-11-07 10:21     ` Nicolas Pouillard
2007-11-07  3:40 ` Christopher L Conway
     [not found] ` <4a051d930711061938u25836a85ud28c610312e5896f@mail.gmail.com>
2007-11-07 10:31   ` tmp123

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).