From: Bertrand Jeannet <Bertrand.Jeannet@inrialpes.fr>
To: caml-list@yquem.inria.fr
Subject: printf "%a" vs sprintf "%a"
Date: Fri, 27 Mar 2009 09:53:32 +0100 [thread overview]
Message-ID: <49CC940C.8030801@inrialpes.fr> (raw)
For people that do not use OCaml batteries, a sprintf function similar
to (Printf|Format).printf can be defined using kfprintf:
let sprintf format =
let buffer = Buffer.create 512 in
let fmt = Format.formatter_of_buffer buffer in
Format.kfprintf
(begin fun fmt ->
Format.pp_print_flush fmt ();
let s = Buffer.contents buffer in
Buffer.clear buffer;
s
end)
fmt
format
The types are different:
Format.fprintf : Format.formatter -> ('a, Format.formatter, unit, unit)
format4 -> 'a
val sprintf : ('a, Format.formatter, unit, string) format4 -> 'a = <fun>
but that is normal, as sprintf should return a string.
Bertrand Jeannet
next reply other threads:[~2009-03-27 8:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-27 8:53 Bertrand Jeannet [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-03-26 16:53 Tiphaine Turpin
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=49CC940C.8030801@inrialpes.fr \
--to=bertrand.jeannet@inrialpes.fr \
--cc=caml-list@yquem.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