From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id CE6F7BB81 for ; Fri, 13 Jan 2006 10:32:14 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0D9WECS006871 for ; Fri, 13 Jan 2006 10:32:14 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA01504 for ; Fri, 13 Jan 2006 10:32:13 +0100 (MET) Received: from mail.tcs.inf.tu-dresden.de (tcs01.inf.tu-dresden.de [141.76.75.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0D9WDrt010598 for ; Fri, 13 Jan 2006 10:32:13 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.tcs.inf.tu-dresden.de (Sun Java System Messaging Server 6.1 HotFix 0.06 (built Nov 11 2004)) with ESMTP id <0IT000L5YYHP3O00@mail.tcs.inf.tu-dresden.de> for caml-list@inria.fr; Fri, 13 Jan 2006 10:32:13 +0100 (MET) Received: from tcs01.inf.tu-dresden.de ([127.0.0.1]) by localhost (mail.tcs.inf.tu-dresden.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05940-04 for ; Fri, 13 Jan 2006 10:32:13 +0100 (MET) Received: from ithif59.inf.tu-dresden.de (ithif59.inf.tu-dresden.de [141.76.75.59]) by mail.tcs.inf.tu-dresden.de (Sun Java System Messaging Server 6.1 HotFix 0.06 (built Nov 11 2004)) with ESMTPS id <0IT000KJSYHPNM00@mail.tcs.inf.tu-dresden.de> for caml-list@inria.fr; Fri, 13 Jan 2006 10:32:13 +0100 (MET) Received: from tews by ithif59.inf.tu-dresden.de with local (Exim 4.50) id 1ExLI5-0002se-48 for caml-list@inria.fr; Fri, 13 Jan 2006 10:32:13 +0100 Date: Fri, 13 Jan 2006 10:31:54 +0100 From: Hendrik Tews Subject: Re: [Caml-list] Request for comments: Printf list conversion In-reply-to: <1137081054.29722.13.camel@localhost> To: Ocaml Message-id: MIME-version: 1.0 Content-type: text/plain; charset=latin-iso8859-15 Content-transfer-encoding: quoted-printable X-Virus-Scanned: amavisd-new at tcs.inf.tu-dresden.de References: <43C61F1F.4030101@barettadeit.com> <1137081054.29722.13.camel@localhost> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 X-Miltered: at nez-perce with ID 43C7739E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43C7739D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; hendrik:01 tews:01 tews:01 caml-list:01 printf:01 printf:01 buf:01 inbetween:01 separators:01 flags:01 omitted:01 damien:01 separators:01 hendrik:01 hacks:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Bill Wood writes: I'm always inspired in my hacks by Common Lisp's (format...) form, which includes a ~{/~} pair containing conversion directives and that consumes a list argument. I don't want to appall you with complexity too soon, but when you think about this, consider the possibility that the list is a list of lists, each of which contains several items that are to be formatted using a a recursively specified (sub) format. This does enhance usability a great deal. I'm sure that there are people who will yelp in protest at this, but I do recommend looking at CL's format as at least one point in this design space. =20=20=20 I doubt anybody will yelp. Having a printf format for 'a list it is just natural to permit arbitrary formats for the 'a elements of the list. Therefore I would suggest something like Printf.bprintf buf "int pair list: %[(%d, %d) %]" [ 1;2;3;4;5 ] Here %[ is the list format and everything inbetween %[ and %] is the format for the list elements (like the %{ .. %} format).=20 It remains to deal with separators that you don't want to print after the last element. Maybe this could be solved by permitting flags for %], like=20 - flag space "% ]": use space separator, omitted after the last element - flag comma "%,]": similar for comma - flag s "%s]": use next argument as format and interpred this format as separator A flag that permits a format would also Virgile Prevosto problem: Virgile Prevosto writes: Le jeu 12 jan 2006 13:55:56 CET, Damien Doligez a =C3=A9crit: >=20 > Yuck. Isn't this type (formatter -> unit -> unit) isomorphic to strin= g, > in the absence of side-effects? Or do you really need separators that > behave differently depending on the state of some reference? >=20 =20=20=20 With Format, yes: you may want to use the pretty-printing features of the module, and for instance add a break hint after each element of the list. Just use=20 Format.printf "int pair list: %[(%d, %d)%s]" [ 1;2;3;4;5 ] "@;<2 2>" BTW, what is the common list solution for printing separators just between the list elements? Bye, Hendrik