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 726B0BBBB for ; Sun, 22 Jan 2006 17:27:48 +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 k0MGRlcn019592 for ; Sun, 22 Jan 2006 17:27:47 +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 RAA32346 for ; Sun, 22 Jan 2006 17:27:47 +0100 (MET) Received: from fork.recoil.org (fork.recoil.org [194.70.3.132]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id k0MGRks1019589 for ; Sun, 22 Jan 2006 17:27:46 +0100 Received: (qmail 32246 invoked by uid 10000); 22 Jan 2006 16:27:45 -0000 Date: Sun, 22 Jan 2006 16:27:45 +0000 From: Anil Madhavapeddy To: Jon Harrop Cc: caml-list Subject: Re: [Caml-list] Pervasives or Printf module ? Message-ID: <20060122162745.GA20731@fork.recoil.org> References: <43D3A058.6030305@yahoo.fr> <200601221534.04835.jon@ffconsultancy.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200601221534.04835.jon@ffconsultancy.com> User-Agent: Mutt/1.5.11 X-Miltered: at concorde with ID 43D3B283.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43D3B282.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; anil:01 anil:01 caml-list:01 pervasives:01 printf:01 printf:01 iter:01 iter:01 wrote:01 partial:01 integer:01 functions:01 computation:01 caml:02 objective:02 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 On Sun, Jan 22, 2006 at 03:34:04PM +0000, Jon Harrop wrote: > > You can do some nice things with printf, like exploit currying: > > # List.iter (Printf.printf "%d ") [1;2;3];; > 1 2 3 - : unit = () > > but it is easy to trip up: > > # List.iter (Printf.printf " %d") [1;2;3];; > 123- : unit = () > > Note: the former prints a space after every integer whereas the latter prints > only a single space at the beginning. To get the latter to act as the former > does, you must beta expand (I think that is the correct technical term) to > postpone the computation of printf " ": This has been improved in 3.09.1 ... from the Changelog: - Printf: better handling of partial applications of the printf functions. Objective Caml version 3.09.1 # List.iter (Printf.printf "%d ") [1;2;3] ;; 1 2 3 - : unit = () # List.iter (Printf.printf " %d") [1;2;3] ;; 1 2 3- : unit = () # List.iter (fun n -> Printf.printf " %d" n) [1;2;3] ;; 1 2 3- : unit = () Hurrah! It always tripped me up :) -- Anil Madhavapeddy http://anil.recoil.org University of Cambridge http://www.cl.cam.ac.uk