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 D7D1FBB81 for ; Thu, 12 Jan 2006 10:19:16 +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 k0C9JGMn021535 for ; Thu, 12 Jan 2006 10:19:16 +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 KAA11087 for ; Thu, 12 Jan 2006 10:19:15 +0100 (MET) Received: from mail.barettadeit.com (h213-255-109-130.albacom.net [213.255.109.130] (may be forged)) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0C9JFCo007281 for ; Thu, 12 Jan 2006 10:19:15 +0100 Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id 7BBDB361589 for ; Thu, 12 Jan 2006 10:23:15 +0100 (CET) Message-ID: <43C61F1F.4030101@barettadeit.com> Date: Thu, 12 Jan 2006 10:19:27 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ocaml Subject: Request for comments: Printf list conversion Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43C61F14.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43C61F13.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; baretta:01 baretta:01 barettadeit:01 printf:01 printf:01 specifier:01 buf:01 buf:01 iter:01 specifier:01 continually:98 ints:01 ints:01 strings:01 int: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 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