From: David Teller <David.Teller@univ-orleans.fr>
To: Jan Kybic <kybic@fel.cvut.cz>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Run-time evaluation of a Printf format string
Date: Thu, 28 Aug 2008 16:10:22 +0200 [thread overview]
Message-ID: <1219932623.7195.20.camel@Blefuscu> (raw)
In-Reply-To: <87hc951cr9.fsf@fel.cvut.cz>
As you may have seen in Pervasives.ml, format6 and string are actually
the same thing. Which means that you can Obj.magic your way around the
problem (gasp!) -- provided you have already checked manually that the
string actually represents the format you're interested in.
Of course, that's a tad risky. If I were you, I'd rather re-implement a
small unparsing language with a format comparable to printf's and a tiny
parser to go with it.
Does this help?
Cheers,
David
P.S.:
If you're interested, I've put together a little bit of documentation
on format* which I think can't be found in OCaml's doc [1]. Look for
"{7 Format4}" in the comments.
[1]
https://forge.ocamlcore.org/plugins/scmsvn/viewcvs.php/trunk/extlib/IO.mli?rev=23&root=batteries&view=auto
On Thu, 2008-08-28 at 15:37 +0200, 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
>
--
David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
Angry researcher: French Universities need reforms, but the LRU act brings liquidations.
next prev parent reply other threads:[~2008-08-28 14:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-28 13:37 Jan Kybic
2008-08-28 14:10 ` David Teller [this message]
2008-08-28 14:58 ` [Caml-list] " Edgar Friendly
2008-08-28 15:01 ` Dave Benjamin
2008-08-28 16:01 ` Stéphane Glondu
2008-08-29 7:34 ` Jan Kybic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219932623.7195.20.camel@Blefuscu \
--to=david.teller@univ-orleans.fr \
--cc=caml-list@yquem.inria.fr \
--cc=kybic@fel.cvut.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox