From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id F0AFBBB81 for ; Thu, 12 Jan 2006 10:40:44 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0C9eiCE010149 for ; Thu, 12 Jan 2006 10:40:44 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA13948 for ; Thu, 12 Jan 2006 10:40:43 +0100 (MET) Received: from smtp4.wanadoo.fr (smtp4.wanadoo.fr [193.252.22.27]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0C9ehwp024055 for ; Thu, 12 Jan 2006 10:40:43 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf0402.wanadoo.fr (SMTP Server) with ESMTP id 5AF811C0016C for ; Thu, 12 Jan 2006 10:40:43 +0100 (CET) Received: from lexifi.com (ATuileries-151-1-6-131.w82-123.abo.wanadoo.fr [82.123.68.131]) by mwinf0402.wanadoo.fr (SMTP Server) with ESMTP id 13C021C001DE; Thu, 12 Jan 2006 10:40:43 +0100 (CET) X-ME-UUID: 20060112094043810.13C021C001DE@mwinf0402.wanadoo.fr Message-ID: <43C621FD.1030308@lexifi.com> Date: Thu, 12 Jan 2006 10:31:41 +0100 From: Jean-Marc EBER User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Alessandro Baretta Cc: Ocaml Subject: Re: [Caml-list] Request for comments: Printf list conversion References: <43C61F1F.4030101@barettadeit.com> In-Reply-To: <43C61F1F.4030101@barettadeit.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 43C6241C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43C6241B.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; lexifi:01 caml-list:01 printf:01 bug:01 ocaml:01 baretta:01 printf:01 specifier:01 buf:01 buf:01 iter:01 specifier:01 caml-list:01 beginner's:01 ocaml: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.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Just for info: Not identical of course, but related is 0003882: Wish: Format.pp_print_list in the bug tracker (and wish list) system of ocaml. Jean-Marc Alessandro Baretta wrote: > I would like to transform the following rather vague idea into a formal > feature request. Before doing this, I would like to know what others > think about it. > > I continually come across the need to pretty-print via Printf a list of > values--for example, let's say an int list. Printf has conversion > specifiers for int, but int list cannot be handled easily. What I > usually end up doing is converting values in the list to strings, > concatenate them, and output the result with the %s conversion specifier. > > Printf.bprintf buf "A beatiful list of ints: [ %s ]\n" (String.concat " > ;" (List.map string_of_int [ 1;2;3;4;5 ] ) > > Obviously, this is radically ineffiecient. A better solution might be > the following. > > Printf.bprintf buf "A beatiful list of ints: [ %t ]\n" (fun buf -> > List.iter (Printf.bprintf buf " %d;") [ 1;2;3;4;5 ] > ) > > The above is adequately fast, but terribly ugly. > > I believe that it should be possible to add a conversion-flag--let me > use '&' as an example--telling the type-system and the Printf module > that the corresponding parameter is a list of values whose type is > determined by the conversion-specifier proper. Let me show what I would > like to be able to write: > > Printf.bprintf buf "A beatiful list of ints: [ %&d ]\n" [ 1;2;3;4;5 ] > > Here, the &-flag would tell the type-system that the first parameter is > an 'a list. The fact that 'a = int is to be inferred from the actual > conversion specifier ('d'). Upon recognizing a %& conversion, Printf > would have to iterate over the corresponding parameter with the > appropriate conversion (format_int_with_conv, in this case). > > Now, of course, the '&' conversion-flag does not settle the issue, as a > parameter like the first one of String.concat would also be needed. > Another issue which is brought up by the idea I have jotted down is how > to handle conversions like '%&a' and '%&t'. > > What do you guys think about all this? > > Alex > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >