<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/1ebeeeaf30083f23aab24519296fd54e"
  from="Sylvain LE GALL &lt;sylvain.le-gall@p...&gt;"
  author="Sylvain LE GALL"
  date="2003-07-05T12:07:01"
  subject="Re: [Caml-list] Printf and format"
  prev="2003/07/47c86cd9157db833717298b5eff903e4"
  next="2003/07/da08ccf0eadd794f5980a4f8a044d49e"
  prev-in-thread="2003/07/47c86cd9157db833717298b5eff903e4"
  next-in-thread="2003/07/bb08176385e0e3626d7033d67ea11fa8"
  prev-thread="2003/07/0dc9c6a5ce74286444025417ac016873"
  next-thread="2003/07/f9cdfa31c48eb391a5653d4f59968d67"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Printf and format">
<msg 
  url="2003/07/6a59432f708b13ca5d40751041049c7a"
  from="Sylvain LE GALL &lt;sylvain.le-gall@p...&gt;"
  author="Sylvain LE GALL"
  date="2003-07-03T16:38:11"
  subject="[Caml-list] Printf and format">
<msg 
  url="2003/07/47c86cd9157db833717298b5eff903e4"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2003-07-05T10:26:52"
  subject="Re: [Caml-list] Printf and format">
<msg 
  url="2003/07/1ebeeeaf30083f23aab24519296fd54e"
  from="Sylvain LE GALL &lt;sylvain.le-gall@p...&gt;"
  author="Sylvain LE GALL"
  date="2003-07-05T12:07:01"
  subject="Re: [Caml-list] Printf and format">
<msg 
  url="2003/07/bb08176385e0e3626d7033d67ea11fa8"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-07-06T10:35:48"
  subject="Re: [Caml-list] Printf and format">
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Sat, Jul 05, 2003 at 12:26:49PM +0200, Pierre Weis wrote:
&gt; &gt; Hello,
&gt; &gt; 
&gt; &gt; I am sorry to ask a so silly question, but i need it for my personnal
&gt; &gt; work, and i could not find it in the archive.
&gt; &gt; 
&gt; &gt; Is there a way to transform string to ( 'a, out_channel, unit, unit)
&gt; &gt; format. I need this function to use it with something like :
&gt; &gt; 
&gt; &gt; Printf.printf (my_fun "X, Y") "coucou";;
&gt; &gt; 
&gt; &gt; I look at the code and see a function scan_format, but it seems to be
&gt; &gt; forbid to use it. 
&gt; &gt; 
&gt; &gt; Any idea ?
&gt; &gt; 
&gt; &gt; Thanks
&gt; &gt; Sylvain LE GALL
&gt; 
&gt; As once announced on this list, the new release of Objective Caml will
&gt; introduce a lot of novelty on the format type.
&gt; 
&gt; Besides new convertion specifiers that you could find in the Printf
&gt; and Scanf documentation (C, S, B, F, !, ...), there are now several
&gt; different new functionalities provided by the new compiler which are
&gt; relevant to your question:
&gt; 
&gt; 0) converting arbitrary format string to a regular strings
&gt; 
&gt; 1) converting CONSTANT strings to the corresponding constant format string
&gt; 
&gt; 2) concatenating format strings (very often feature 0 and 1 are used
&gt; in conjonction just to implement format strings concatenation).
&gt; 
&gt; Back to your problem: the features described here may your for some
&gt; ``my_fun'' functions, but the general case is not properly covered by
&gt; them. What we need is a general function that reads a format from
&gt; within a string that is NOT a constant. This is a kind of dynamic
&gt; convertion reminiscent of int_of_string or float_of_string, that
&gt; checks that the string can be indeed considered as an integer of
&gt; floatting point number.
&gt; 
&gt; I propose (and have implemented for my own programming of a general
&gt; translation function) a new function [read_format], such that
&gt; 
&gt; [read_format pat s] returns the string [s] as a format string that has
&gt; the same type (hence the same ``printf meaning'') as [pat], the first
&gt; format string argument.
&gt; 
&gt; For instance,
&gt; 
&gt; read_format "The number %d is odd" "Le nombre %d est impair"
&gt; 
&gt; returns "Le nombre %d est impair" as a format string with the same
&gt; type as "The number %d is odd".
&gt; 
&gt; This function is more general that the one above since now in
&gt; [read_format pat s] the string [s] is not mandatorily an immediate
&gt; string constant: it can be obtained from an arbitrary computation, as
&gt; read from a file.
&gt; 
&gt; The Typechecking of read_format would be:
&gt; 
&gt; read_format :
&gt;  ('a, 'b, 'c, 'd) format -&gt; string -&gt; ('a, 'b, 'c, 'd) format
&gt; 
&gt; If considered useful, this function could be added, for instance as
&gt; part of a new internationalization module.

Hello,

you read my mind. Indeed, the question concern an internationalization
module ( let's call libgettext-ocaml ). It is basically a binding of
gettext. 

But, for handling certain apsect of gettext it needs printf like
capability. But the printf like capibility, as printf, use a non constant
string ( returned by a function dngettext... or so ). That's the reason
why i am looking after something which correpsond to this things.

If people at INRIA could include some kind of read_format, it could be
very useful.

Thanks a lot
Sylvain LE GALL

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

