From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id D33927EE99 for ; Wed, 25 Dec 2013 15:38:57 +0100 (CET) Received-SPF: Neutral (mail3-smtp-sop.national.inria.fr: domain of simon.cruanes.2007@m4x.org does not assert whether or not 129.104.30.34 is permitted sender) identity=pra; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=vQpi=WA=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="simon.cruanes.2007@m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of SRS0=vQpi=WA=m4x.org=simon.cruanes.2007@bounces.m4x.org designates 129.104.30.34 as permitted sender) identity=mailfrom; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=vQpi=WA=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="SRS0=vQpi=WA=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@mx1.polytechnique.org designates 129.104.30.34 as permitted sender) identity=helo; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=vQpi=WA=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="postmaster@mx1.polytechnique.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsMBAIHtulKBaB4inGdsb2JhbABYg0ODVKNxlA8WDgEBAQEBCAsJCRQogiYBAQQjBEcbCwQhHQICRRIZEodeAxEECa98khwDhlwXjzqCWIFIBJgXgTCUEg X-IPAS-Result: AsMBAIHtulKBaB4inGdsb2JhbABYg0ODVKNxlA8WDgEBAQEBCAsJCRQogiYBAQQjBEcbCwQhHQICRRIZEodeAxEECa98khwDhlwXjzqCWIFIBJgXgTCUEg X-IronPort-AV: E=Sophos;i="4.95,548,1384297200"; d="scan'208,217";a="42270833" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 25 Dec 2013 15:38:57 +0100 Received: from android-601a6482245bbd6.home (AClermont-Ferrand-652-1-211-198.w86-209.abo.wanadoo.fr [86.209.98.198]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id C4C6A140912E6 for ; Wed, 25 Dec 2013 15:38:54 +0100 (CET) User-Agent: K-9 Mail for Android In-Reply-To: <52BA4AF0.7040203@riken.jp> References: <52BA4AF0.7040203@riken.jp> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----42OVKMXVEV24RKKDNBRTLBNMD74R48" From: Simon Cruanes Date: Wed, 25 Dec 2013 15:38:47 +0100 To: caml-list@inria.fr Message-ID: <4d2750c9-a492-447d-b65d-0a5253361576@email.android.com> X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Wed Dec 25 15:38:56 2013 +0100 (CET)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.020465, queueID=3DBE8140912FA X-Org-Mail: simon.cruanes.2007@polytechnique.org Subject: Re: [Caml-list] signature of a lazy Printf.sprintf-like ------42OVKMXVEV24RKKDNBRTLBNMD74R48 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 ------42OVKMXVEV24RKKDNBRTLBNMD74R48 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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.

--
Simon ------42OVKMXVEV24RKKDNBRTLBNMD74R48--