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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id B3228BB84 for ; Thu, 28 Aug 2008 16:58:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkMBAORZtkjRVYT3jmdsb2JhbACSAD4BAQEBCQMKBw+gO4cXAQI X-IronPort-AV: E=Sophos;i="4.32,286,1217800800"; d="scan'208";a="28588423" Received: from an-out-0708.google.com ([209.85.132.247]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Aug 2008 16:58:24 +0200 Received: by an-out-0708.google.com with SMTP id b2so64336ana.102 for ; Thu, 28 Aug 2008 07:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=dqdc5lgAhp2xVKzAjQP5LZumCegrIyBb/bN+rB78Ceo=; b=PbhkD9vyx5i3JzT3E1z2WYEWvV2L7vmtg5wuFetqblFVpJviNqTMv5SvfXLVsM1jZl l4ZLB13qZvwgCYgZUlJH/IB5cUJJDvFhHn+TolOkYnWppX+zJgvdVY7nV2PoxmXfiq5G fGzReCmFhpz6DKTbSpFusmsl8/6DUMm5YIg/4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=fqqoj1HIPBV08JxAwPNNUK8C217g9DzTjAMsgfFxxx//J2Bw8UNHpVl4nf+NvSwSpb 410zD7gtta/zkIOvhn987Q+ABSSqu0fSq4vjBTlA3hTd+1bzcc2D5m0BMEaX+OPpioHR nIoBnbIcz7/bJ8xVI5Ok6HGGEi54IIMUv9Z/k= Received: by 10.100.11.7 with SMTP id 7mr1748719ank.32.1219935502585; Thu, 28 Aug 2008 07:58:22 -0700 (PDT) Received: from ?192.168.0.138? ( [97.87.208.12]) by mx.google.com with ESMTPS id d38sm1744249and.20.2008.08.28.07.58.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 28 Aug 2008 07:58:21 -0700 (PDT) Message-ID: <48B6BD09.1040200@gmail.com> Date: Thu, 28 Aug 2008 09:58:17 -0500 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Jan Kybic , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Run-time evaluation of a Printf format string References: <87hc951cr9.fsf@fel.cvut.cz> In-Reply-To: <87hc951cr9.fsf@fel.cvut.cz> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; run-time:01 printf:01 printf:01 sprintf:01 %03:01 ocaml:01 pervasives:01 sprintf:01 edgar:98 img:98 height:98 wrote:01 integer:01 caml-list:01 strings:01 Jan Kybic wrote: > Hello, > I would need an equivalent of Printf.sprintf where the > format string is not constant, it is read from the command line. > The motivation is to let the user specify a template for file names, > such as "img%03d.png". Can this be achieved in Ocaml? It seems not, as > Pervasives.string_of_format only accepts constant strings. > Or is there some external library useful for this task? > > For the moment I have started to implement it myself for the limited > set of format specifications I will need but if there is some more > elegant solution I would be interested to hear about it. > > Thanks, > > Jan > What arguments will you pass to your sprintf command? Just a single integer? Or do you have multiple values that can be inserted into the template. For templating like this, you probably want the different %x's to refer to different values in your program (i.e. %d - count number, %w - width of image, %h - height of image, etc). For this use, you'll have to write your own handler of the input "format" strings, and you won't rely on sprintf to do the work. E