caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Simon Cruanes <simon.cruanes.2007@m4x.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] signature of a lazy Printf.sprintf-like
Date: Wed, 25 Dec 2013 15:38:47 +0100	[thread overview]
Message-ID: <4d2750c9-a492-447d-b65d-0a5253361576@email.android.com> (raw)
In-Reply-To: <52BA4AF0.7040203@riken.jp>

[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]

I can't give much detail from my phone, sorry, but here is a close equivalent I use for debugging:



let debug l format =
  let b = Buffer.create 15 in
  if l <= !debug_level
    then Printf.kbprintf
        (fun b -> print_endline (Buffer.contents b))
        b format
    else
      Printf.ifprintf b format


With .mli:

val debug : int -> ('a, Buffer.t, unit, unit) format4 -> 'a


Here I use buffer printers, but you can try to adapt so that it uses string printers (see the difference between sprintf and bprintf). With some callback function you should be able to capture the content of a string or buffer in a lazy value; you might also find ifprintf useful. Hope this helps! 

Merry Christmas :)


Francois Berenger <berenger@riken.jp> a écrit :
>Hello,
>
>Is is possible to create a sprintf which is lazy?
>
>Especially, I don't know what signature it should have
>in the .mli file.
>
>I am fighting with types because the function
>is supposed to accept a variable number of parameters
>after the format string.
>If I manage to create a compilable signature, then
>I cannot any-more use a variable number of parameters.
>
>Merry Christmas,
>Francois.
>
>-- 
>Caml-list mailing list.  Subscription management and archives:
>https://sympa.inria.fr/sympa/arc/caml-list
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>Bug reports: http://caml.inria.fr/bin/caml-bugs

-- 
Simon

[-- Attachment #2: Type: text/html, Size: 1605 bytes --]

      reply	other threads:[~2013-12-25 14:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-25  3:03 Francois Berenger
2013-12-25 14:38 ` Simon Cruanes [this message]

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=4d2750c9-a492-447d-b65d-0a5253361576@email.android.com \
    --to=simon.cruanes.2007@m4x.org \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).