caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] signature of a lazy Printf.sprintf-like
@ 2013-12-25  3:03 Francois Berenger
  2013-12-25 14:38 ` Simon Cruanes
  0 siblings, 1 reply; 2+ messages in thread
From: Francois Berenger @ 2013-12-25  3:03 UTC (permalink / raw)
  To: caml-list

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.

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

* Re: [Caml-list] signature of a lazy Printf.sprintf-like
  2013-12-25  3:03 [Caml-list] signature of a lazy Printf.sprintf-like Francois Berenger
@ 2013-12-25 14:38 ` Simon Cruanes
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Cruanes @ 2013-12-25 14:38 UTC (permalink / raw)
  To: caml-list

[-- 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 --]

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

end of thread, other threads:[~2013-12-25 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-25  3:03 [Caml-list] signature of a lazy Printf.sprintf-like Francois Berenger
2013-12-25 14:38 ` Simon Cruanes

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).