From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 468827EFCD for ; Tue, 28 Oct 2014 10:20:19 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.218.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.218.45 as permitted sender) identity=mailfrom; client-ip=209.85.218.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oi0-f45.google.com) identity=helo; client-ip=209.85.218.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-oi0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgUBAGZeT1TRVdotlWdsb2JhbABcg2JYBIMCujiQZwqHTQKBEgcWAREBAQEBBw0JCRIwhAMBAQQBAg8RBBkBGxILAQMMBgULAwoCAgkdAgIiAREBBQEKEgYTCAoICIgJAQMSDalfboszgXKDEYkOChknAwpnhVEBAQEBAQEEAQEBAQEBFgEFDoEejykzB4J3gVQFhRUFjXSDQYcSgTE8hjqEdYUSggwYKYUsPC+CSwEBAQ X-IPAS-Result: AgUBAGZeT1TRVdotlWdsb2JhbABcg2JYBIMCujiQZwqHTQKBEgcWAREBAQEBBw0JCRIwhAMBAQQBAg8RBBkBGxILAQMMBgULAwoCAgkdAgIiAREBBQEKEgYTCAoICIgJAQMSDalfboszgXKDEYkOChknAwpnhVEBAQEBAQEEAQEBAQEBFgEFDoEejykzB4J3gVQFhRUFjXSDQYcSgTE8hjqEdYUSggwYKYUsPC+CSwEBAQ X-IronPort-AV: E=Sophos;i="5.04,801,1406584800"; d="scan'208";a="85021199" Received: from mail-oi0-f45.google.com ([209.85.218.45]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Oct 2014 10:20:18 +0100 Received: by mail-oi0-f45.google.com with SMTP id i138so174774oig.4 for ; Tue, 28 Oct 2014 02:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=6PLQM1PHUtOrJncloLHHoNg2hyR+lAGP1fCc+kxfDx4=; b=i1iagR5ASOlXqPFrA6bfOQ+pv9reFBkgZ4fTLfy8sktIcT/W+LJFfEfEa1rpx2qRE3 vEGuLkt4yi6lFgaWyfl9fp1CBzmtPjycsYnNFiUuVWD+ykz0naq+NrlPAFK1C1NiQSM9 zlFsrudaPB/2yNXpfnsqqwsc1cmpspcA3SPwRt74gSLcLgtvLLs0BkzzTvJMAdnDP/0j cqc8AGU/hVkw2UVwBC2PjJjcO9W7+gH5l+2ARjQUJjWOnUVbrzLgyFRbpNUxXDvOVmbp l+IGp5NjRWvVWVg2zESbWlnhQzb9XoqeUIHbJmV66gMVBhBQQd1E/NWzid4PN286LfEj 6Etg== X-Received: by 10.182.33.138 with SMTP id r10mr325265obi.67.1414488016944; Tue, 28 Oct 2014 02:20:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.105.196 with HTTP; Tue, 28 Oct 2014 02:19:34 -0700 (PDT) In-Reply-To: References: <000001cff20f$57052560$050f7020$@metastack.com> <8D9D2D7B6A29486D80BB692EC24DBE06@erratique.ch> From: Gabriel Scherer Date: Tue, 28 Oct 2014 10:19:34 +0100 Message-ID: To: David Allsopp Cc: OCaml List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Vagaries of Printf variants If you know from the start that you need this flexibility, the easiest way is probably to use Printf.bprintf from the start, which is reasonably efficient and flexible (or write your fprintf-formats with %s rather than %a). If you specifically need to convert code that uses (f)printf with minimal changes, you have the problem that your %a/%t functions work with out_channel, not strings. The simplest way out is probably to use Unix.pipe (which is available on Windows) to create an out_channel that you write into and read back the content as a string. On Tue, Oct 28, 2014 at 10:04 AM, David Allsopp wr= ote: > Daniel B=C3=BCnzli wrote: >> Le lundi, 27 octobre 2014 =C3=A0 18:56, David Allsopp a =C3=A9crit : >> > but I'm sure there's a reason for its being that way! >> >> You may be interested in reading this: >> >> http://gallium.inria.fr/blog/format6/ > > Thanks, that is enlightening! I guess the thing that gets "in the way" is= the design decision to make %a operate on the printf-behaviour (i.e. for f= printf, it writes to a channel, for bprintf it writes to a buffer) rather t= han making %a and %t *always* return a string. > >> P.S. If you are using formatters the problem is less acute. Nowadays you >> can simply define formatters for each of your types with: >> >> pp : Format.formatter -> t -> unit >> >> and a to_string function is one `Format.asprintf "%a" pp` away. > > I was abusing terminology - by formatters I meant printf functions i.e. s= electing between ikfprintf, kfprintf, etc. in the same functions. > > I haven't looked at the 4.02 sources, but for what I'm doing in 4.01, wha= t would actually be useful would be if Printf.mkprintf were public so that = I could supply an alternate function for output_string (i.e. allow Printf.p= rintf to proceed entirely as normal but do something ever-so-slightly diffe= rent with the final result - and with a different format6 from using ksprin= tf). > > > David > > -- > 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