From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 76A54BC68 for ; Sat, 11 Nov 2006 22:26:51 +0100 (CET) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kABLQop7023737 for ; Sat, 11 Nov 2006 22:26:51 +0100 Received: from db2.internal (db2.internal [10.202.2.12]) by frontend1.messagingengine.com (Postfix) with ESMTP id EFC42DC5E13; Sat, 11 Nov 2006 16:26:42 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by db2.internal (MEProxy); Sat, 11 Nov 2006 16:26:44 -0500 X-Sasl-enc: ixnWiZ3AIksoCYo4oHJOeH4nPiWjhqtAY5syoAGgRHsd 1163280404 Received: from adsl-75-26-47-5.dsl.sndg02.sbcglobal.net (adsl-75-26-47-5.dsl.sndg02.sbcglobal.net [75.26.47.5]) by mail.messagingengine.com (Postfix) with ESMTP id 2CA301C920; Sat, 11 Nov 2006 16:26:44 -0500 (EST) Date: Sat, 11 Nov 2006 13:26:38 -0800 (PST) From: Martin Jambon X-X-Sender: martin@droopy To: Peter Gregory Cc: ermine@ermine.pp.ru, caml-list@inria.fr Subject: Re: [Caml-list] printf and positional specifier In-Reply-To: <45563D79.4070207@cis.strath.ac.uk> Message-ID: References: <20061111201226.GA14282@ermine.home> <4556342C.10109@cis.strath.ac.uk> <45563D79.4070207@cis.strath.ac.uk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-j-chkmail-Score: MSGID : 4556401A.000 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 4556401A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; printf:01 specifier:01 ocaml:01 printf:01 fprintf:01 libref:01 specifies:01 val:01 1977:98 wrote:01 wrote:01 char:01 char:01 caml-list:01 jambon:01 On Sat, 11 Nov 2006, Peter Gregory wrote: > Martin Jambon wrote: >> On Sat, 11 Nov 2006, Peter Gregory wrote: >> >>> Anastasia Gornostaeva wrote: >>>> Hello. >>>> >>>> $ ocaml >>>> Objective Caml version 3.09.3 >>>> >>>> # open Printf;; >>>> # printf "%2$d %1$s" "abc" 2;; >>>> Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' >>>> >>>> >>>> How? >>>> >>>> ermine >>>> >>> >>> Hi Ermine, >>> >>> I'm not sure that I understand your question. I think to achieve what you >>> seem to be trying, you would simply write: >>> >>> # printf "%d %s" 2 "abc";; >>> >>> You just put the parameters in the order they came in the string. Does >>> that help, it seems like perhaps you needed more than that. >> >> The dollar stuff is real, although I have no idea of how to make it work. >> It's the last paragraph in the description of Printf.fprintf: >> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html >> >> > > I take a different reading to you Martin, although I think it is confusing. > I believe that the number specified before the dollar sign is the argument > that specifies the /precision/ of the output. > > So, it is not to specify the argument to print, but the argument to use as > precision. That said, I tried it in the context they suggest and I couldn't > make it work! Here is what I tried: # open Printf;; # let x = 1234.5678;; val x : float = 1234.5678 (* Just for fun *) # printf "%.2f %.*f" x 3 x;; 1234.57 1234.568- : unit = () (* I understand that the following should print "1234.57 1234.57": *) # printf "%.2f %.*1$f" x x;; Bad conversion %1, at char number 5 in format string ``%.2f %.*1$f'' Martin -- Martin Jambon, PhD http://martin.jambon.free.fr