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 8D7587F860 for ; Thu, 6 Mar 2014 17:47:15 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of benoit.vaugon@gmail.com) identity=pra; client-ip=209.85.215.54; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="benoit.vaugon@gmail.com"; x-sender="benoit.vaugon@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of benoit.vaugon@gmail.com designates 209.85.215.54 as permitted sender) identity=mailfrom; client-ip=209.85.215.54; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="benoit.vaugon@gmail.com"; x-sender="benoit.vaugon@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-la0-f54.google.com) identity=helo; client-ip=209.85.215.54; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="benoit.vaugon@gmail.com"; x-sender="postmaster@mail-la0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqgCAAWmGFPRVdc2lGdsb2JhbABag0FLDKpZjWyIW4EQCBYOAQEBAQcLCwkSKoIlAQEBAwFAARsSCwEDAQsGBQQHGiEhAQERAQUBChIGExKHUgEDCQgNojOMX4MOlUcKGScDCmSGEREBBQyMOIITBAeEOASWUYFtgTKLMYNaGCmEWzs X-IPAS-Result: AqgCAAWmGFPRVdc2lGdsb2JhbABag0FLDKpZjWyIW4EQCBYOAQEBAQcLCwkSKoIlAQEBAwFAARsSCwEDAQsGBQQHGiEhAQERAQUBChIGExKHUgEDCQgNojOMX4MOlUcKGScDCmSGEREBBQyMOIITBAeEOASWUYFtgTKLMYNaGCmEWzs X-IronPort-AV: E=Sophos;i="4.97,601,1389740400"; d="scan'208";a="51555995" Received: from mail-la0-f54.google.com ([209.85.215.54]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Mar 2014 17:47:13 +0100 Received: by mail-la0-f54.google.com with SMTP id mc6so1976120lab.13 for ; Thu, 06 Mar 2014 08:47:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MhPKI1XQGPeQLjJO37u195UBXfdjNr0qiTNiqnCa4/w=; b=xHm8Sux2qK8I/EZK2lX1LTeiGdinu4jiMhsZvNPB+IhfvpTO1QKqmKhNCbVfJgT+fO MlXow061Eq/i+cNgoxd5CHYK0X1NTlO6OqRMSlpXYRrvFJ2nHu0pbKaA9dK6qZfAHkeQ JXBj9lFn7eXq01QjfWWBV3r+EgsgVnmgHXseUmsTXtx7hAPmy1ZS5OHXPshlJdbMIypk TTJEVg/rs85Xi4lfJyCk17Pbaw8+Vhs+opFim80QfT+artQVTDnEb5Ef897qWE8hYBzQ 8NySE7CLeIc6fHNwQyy4NpYhcVtY5woGBtXhucJuDl+vKalMGDPKPaSUnFS8DmEHa8ry bbtQ== MIME-Version: 1.0 X-Received: by 10.112.170.234 with SMTP id ap10mr8168583lbc.23.1394124432490; Thu, 06 Mar 2014 08:47:12 -0800 (PST) Received: by 10.152.201.70 with HTTP; Thu, 6 Mar 2014 08:47:12 -0800 (PST) In-Reply-To: <5318A3A8.8050402@gmail.com> References: <5318A3A8.8050402@gmail.com> Date: Thu, 6 Mar 2014 17:47:12 +0100 Message-ID: From: Benoit Vaugon To: Matthieu Dubuget Cc: caml-list Content-Type: multipart/alternative; boundary=001a11c373ec9246e204f3f2e3d9 Subject: Re: [Caml-list] I never succeeded in using Format --001a11c373ec9246e204f3f2e3d9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, The set_margin function configure the std_formatter, ie the formatter of the standard output (the one used by printf). To change the margin when printing in a buffer, you can run something like this : # open Format;; # let buf =3D Buffer.create 16;; val buf : Buffer.t =3D # let formatter =3D formatter_of_buffer buf;; val formatter : Format.formatter =3D # pp_set_margin formatter 9;; - : unit =3D () # fprintf formatter "@[111,@,222,@,333,@,444,@,555,@,666@]@.";; - : unit =3D () # Buffer.contents buf;; - : string =3D "111,222,\n333,444,\n555,666\n" Best regards, Beno=EEt Vaugon. 2014-03-06 17:34 GMT+01:00 Matthieu Dubuget : > Is the following behaviour expected, or a misunderstanding of mine? > > In short, I'd like to use the Format module to prepare an > output inside a Buffer.t. But a basic box does not > break lines as I would expect, while printf does. > > OCaml version 4.01.0 > > # open Format;; > # printf "@[111,@,222,@,333,@,444,@,555,@,666@]@.";; > 111,222,333,444,555,666 > - : unit =3D () > # set_margin 9;; > - : unit > =3D () > # printf "@[111,@,222,@,333,@,444,@,555,@,666@]@.";; > 111,222, > 333,444, > 555,666 > - : unit > =3D () > # sprintf "@[111,@,222,@,333,@,444,@,555,@,666@]@.";; > - : string > =3D > "111,222,333,444,555,666\n" > > Why doesn't sprintf exhibit the same behaviour as printf? > Trying with fprintf... > > # fprintf str_formatter "@[111,@,222,@,333,@,444,@,555,@,666@]@.";; > - : unit > =3D () > # flush_str_formatter ();; > - : string > =3D > "111,222,333,444,555,666\n" > > -- > Matthieu Dubuget > > > -- > 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 > --001a11c373ec9246e204f3f2e3d9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,

The set_margin function configure the std_formatter, ie the formatt= er of the standard output (the one used by printf). To change the margin wh= en printing in a buffer, you can run something like this :

# open Format;;
# = let buf =3D Buffer.create 16;;
val buf : Buffer.t =3D <abstr>
#= let formatter =3D formatter_of_buffer buf;;
val formatter : Format.form= atter =3D <abstr>
# pp_set_margin formatter 9;;
- : unit =3D ()
# fprintf formatter &qu= ot;@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;
- : unit = =3D ()
# Buffer.contents buf;;
- : string =3D "111,222,\n333,444= ,\n555,666\n"

Best regards,
Beno=EEt Vaugon.



2014-03-06 17:34 GMT+01= :00 Matthieu Dubuget <matthieu.dubuget@gmail.com>:<= br>
Is the following behaviour expected, or a mi= sunderstanding of mine?

In short, I'd like to use the Format module to prepare an
output inside a Buffer.t. But a basic <hov> box does not
break lines as I would expect, while printf does.

OCaml version 4.01.0

# open Format;;
# printf "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;<= br> 111,222,333,444,555,666
- : unit =3D ()
# set_margin 9;;
- : unit
=3D ()
# printf "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;<= br> 111,222,
333,444,
555,666
- : unit
=3D ()
# sprintf "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;=
- : string
=3D
"111,222,333,444,555,666\n"

Why doesn't sprintf exhibit the same behaviour as printf?
Trying with fprintf…

# fprintf str_formatter "@[<hov0>111,@,222,@,333,@,444,@,555,@,6= 66@]@.";;
- : unit
=3D ()
# flush_str_formatter ();;
- : string
=3D
"111,222,333,444,555,666\n"

--
Matthieu Dubuget


--
Caml-list mailing list.  Subscription management and archives:
ht= tps://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

--001a11c373ec9246e204f3f2e3d9--