From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 438CC7EE25 for ; Wed, 6 Nov 2013 13:44:15 +0100 (CET) Received-SPF: Neutral (mail3-smtp-sop.national.inria.fr: domain of simon.cruanes.2007@m4x.org does not assert whether or not 129.104.30.34 is permitted sender) identity=pra; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=7Pue=UP=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="simon.cruanes.2007@m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of SRS0=7Pue=UP=m4x.org=simon.cruanes.2007@bounces.m4x.org designates 129.104.30.34 as permitted sender) identity=mailfrom; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=7Pue=UP=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="SRS0=7Pue=UP=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@mx1.polytechnique.org designates 129.104.30.34 as permitted sender) identity=helo; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=7Pue=UP=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="postmaster@mx1.polytechnique.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtkCACE5elKBaB4inGdsb2JhbABahxq9WxYOAQEBAQEICwkJFCiCJQEBBAEjBFIFCwshIQICDwVJiA4GrCCSQpJLgUUDmAuVMg X-IPAS-Result: AtkCACE5elKBaB4inGdsb2JhbABahxq9WxYOAQEBAQEICwkJFCiCJQEBBAEjBFIFCwshIQICDwVJiA4GrCCSQpJLgUUDmAuVMg X-IronPort-AV: E=Sophos;i="4.93,647,1378850400"; d="scan'208";a="34013353" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 06 Nov 2013 13:44:10 +0100 Received: from emmental.inria.fr (emmental.inria.fr [128.93.0.14]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id B0B7614007959; Wed, 6 Nov 2013 13:44:09 +0100 (CET) Date: Wed, 6 Nov 2013 13:44:08 +0100 From: Simon Cruanes To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com> Cc: OCaml Message-ID: <20131106124408.GQ1501@emmental.inria.fr> References: <527A389B.9070408@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="JHjDRUnf1JOMxzko" Content-Disposition: inline In-Reply-To: <527A389B.9070408@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Wed Nov 6 13:44:09 2013 +0100 (CET)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.000516, queueID=CD4501400894F X-Org-Mail: simon.cruanes.2007@polytechnique.org Subject: Re: [Caml-list] is there a way for turning strings to "format"s? --JHjDRUnf1JOMxzko Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Le Wed, 06 Nov 2013, Matej Kosik a =C3=A9crit : > Hi, >=20 > I would like to ask, how to do something like: >=20 > let computed_format =3D Printf.sprintf "%%0%dd" 5 in > Printf.printf computed_format 42 >=20 > The above code is rejected, because "computed_format" is of type "string"= whereas >=20 > ('a -> 'b, out_channel, unit) format =3D > ('a -> 'b, out_channel, unit, unit, unit, unit) format6 >=20 > type was expected. >=20 > My question is: is it possible to turn strings to values that would be ac= cepted by Printf.printf as its first parameter? I don't think you can in general, because format strings are typed (so that the compiler can check the correctness of Printf.printf calls). However, you could try something along let computed_format =3D Printf.sprintf "%%0%d%d" 5 in print_string (computed_format 42) --=20 Simon --JHjDRUnf1JOMxzko Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) iQIcBAEBAgAGBQJSejmYAAoJEErAHQhJqmK2HVsQAITNk5mArz8qPJHFzbOEdnhe +CsC8YGf5DI5Df+QlU45waBUKC77LUdJVXlHwHxcXHR+JsYuID5c/x7tq/ByxP0G eY8MZQ8VHZKgpEgDRKn7L5D1LihCcSDplANb0K+cn5Q8fuxP6VJH81zrw+tT7iWP VaZfFZCHachLJRi9EKzaL3x1d7dzMyaYnU8SHFnwh1wlcgfm4MBoO8yiczcxrUwp cpG1FMcjFhPuLN4bg0X0u/sy03sYuiulqRvz3Y7oiLnDNfASZQWS3jcxGDorkNdh vMEBeZOtWrDUe3ITUbpJN2lw5bx0ZOcN3GBOUos3u0T1xffzxS+m3yugWBeTjzL8 PMMC8biCpdtrdInbQKWXx9jaF1c+GDyYyYBc0mi4g/s68Al3XeMbVBcDB21vViTL C1LBvSsvji+JRHzMt0+C0rQSjdfN2TYIfcve+JzE08jUshEatBPtTH+uPHk3tZxS 6uwvum3IuQiXMcxx/YVAZV5YjlHLyprPHZQiNyp3yCZCD3uVBZtFHdrfDGwcb72a ukf2L3PplByPsa02NS1ysmnNb2Vc3ulQD71qXR0Nq/u463okycTc7oz+J+Rm6fLP +be3WI9KR/yg+AJPGiWVpLN2wH922aLkQ40Gq92+yO+NxEukLtqq7qF93FjvBgWb CvC8U4d+DZ/19zKPd6JE =TOWX -----END PGP SIGNATURE----- --JHjDRUnf1JOMxzko--