Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "till.varoquaux" <till.varoquaux@gmail.com>
Cc: tmp123 <tmp123@menta.net>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] log function without evaluate arguments
Date: Wed, 07 Nov 2007 11:21:23 +0100	[thread overview]
Message-ID: <1194430860-sup-6629@port-ext2.ensta.fr> (raw)
In-Reply-To: <9d3ec8300711061040l424aac69y4b859a029d815089@mail.gmail.com>

Excerpts from till.varoquaux's message of Tue Nov 06 19:40:19 +0100 2007:
> On 11/6/07, Nicolas Pouillard <nicolas.pouillard@gmail.com> wrote:
> > Excerpts from tmp123's message of Tue Nov 06 18:05:48 +0100 2007:
> > > 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.
> >
> > Have a look to the Printf.ifprintf [1] function, it does exactly what you want.
> >
> > Regards,
> >
> Actually it doesn't:
> 
>    log (lazy (Printf.printf "%s" (awfully_long_computation ())))
> 
> when log_val is false (or sylvain's solution, which I prefer), will
> not behave like
> 
>    Printf.ifprinf "%s" (awfully_long_computation ())
> 
> (it won't evaluate its arguments).

Of course but you should use %a:

let log fmt = if debug_mode then Printf.fprintf fmt else Printf.ifprintf fmt;;

let awfully_long_computation' oc () = Printf.fprintf "%s" (awfully_long_computation ());;

log "%a" awfully_long_computation' ()

Regards,

-- 
Nicolas Pouillard aka Ertai


  parent reply	other threads:[~2007-11-07 10:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-06 17:05 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 [this message]
2007-11-07  3:40 ` Christopher L Conway
     [not found] ` <4a051d930711061938u25836a85ud28c610312e5896f@mail.gmail.com>
2007-11-07 10:31   ` tmp123

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1194430860-sup-6629@port-ext2.ensta.fr \
    --to=nicolas.pouillard@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=till.varoquaux@gmail.com \
    --cc=tmp123@menta.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox