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 33979BB81 for ; Thu, 12 Jan 2006 10:56:33 +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 k0C9uW31012134 for ; Thu, 12 Jan 2006 10:56:32 +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 KAA14133 for ; Thu, 12 Jan 2006 10:56:32 +0100 (MET) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0C9uVQM012129 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 12 Jan 2006 10:56:32 +0100 Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id A5A24202484; Thu, 12 Jan 2006 10:56:31 +0100 (CET) Received: from pc9-152 (pc9-152 [129.175.9.152]) by smtp.lri.fr (Postfix) with ESMTP id 5A5B6CED98; Thu, 12 Jan 2006 10:56:30 +0100 (CET) Received: from filliatr by pc9-152 with local (Exim 3.36 #1 (Debian)) id 1EwzBZ-0004aS-00; Thu, 12 Jan 2006 10:56:01 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <17350.10156.454589.275252@gargle.gargle.HOWL> Date: Thu, 12 Jan 2006 10:55:56 +0100 To: Alessandro Baretta Cc: Ocaml Subject: Re: [Caml-list] Request for comments: Printf list conversion In-Reply-To: <43C61F1F.4030101@barettadeit.com> References: <43C61F1F.4030101@barettadeit.com> X-Mailer: VM 7.19 under Emacs 21.4.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at concorde with ID 43C627D0.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43C627CF.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 printf:01 filliatre:01 filliatr:01 lri:01 baretta:01 printf:01 bug:01 val:01 fprintf:01 fmt:01 val:01 separators:01 filliatre:01 lri: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 Hello, Alessandro Baretta writes: > 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. I recently submitted a similar wish on the bug tracking system, which is slightly more general than your proposal: http://caml.inria.fr/mantis/view.php?id=3882 Meanwhile, I'm using a rather different solution than yours, that is a custom function val print_list : (formatter -> 'a -> unit) -> formatter -> 'a list -> unit that I use with %a, e.g. fprintf fmt "this is the list %a" (print_list pp_print_int) [1;2;3] I actually use a more general version of print_list that allows a separator to be specified (to be printed in between the list elements): val print_list : ?sep:(formatter -> unit -> unit) -> (formatter -> 'a -> unit) -> formatter -> 'a list -> unit which comes with a handy list of predefined separators: val space : formatter -> unit -> unit val newline : formatter -> unit -> unit val comma : formatter -> unit -> unit val semi : formatter -> unit -> unit val nothing : formatter -> unit -> unit etc. Hope this helps, -- Jean-Christophe Filliātre (http://www.lri.fr/~filliatr)