[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-12-01 (10:18) |
From: | Hendrik Tews <tews@t...> |
Subject: | Re: [Caml-list] printf format strings |
Jonathan Roewen <jonathan.roewen@gmail.com> writes: { fmt %}: convert a format string argument. The argument must have the same type as the internal format string fmt. And how to use it? I get Bad format `%{' in the toplevel. My toplevel accepts it, but does nothing on it: # Printf.printf "%{%d%s%}" "kkkk\n" ;; This expression has type (int -> string -> 'a, 'b, 'c, int -> string -> 'a) format4 but is here used with type (int -> string -> 'a, 'b, 'c, 'a) format4 This is expected, because kkkk has the wrong type. # Printf.printf "%{%d%s%}" "kk%dkk%s\n" ;; - : unit = <unknown constructor> This should print something I guess. The "unknown constructor" looks very suspicious. Maybe the %{ format is meant to generate random strings??? # String.escaped(Printf.sprintf "%{kkk%}" "kkk\n") ;; - : string = "\\136LÛ\\149*\\000\\000\\000 óY\\149*\\000\\000\\0000\\tî\\149*\\000\\000" ;-) Note that there is a typo in the docs: There is no format %\(...%\): # Printf.printf "%\\(aaa%\\)";; Bad conversion %\, at char number 0 in format string ``%\(aaa%\)'' It is %(...%): # Printf.printf "%(aaa%)";; - : ('_a, '_b, '_c, '_a) format4 -> unit = <fun> However, it does not seem to work either: # Printf.printf "%(aaa%)" "bbbb";; - : unit = <unknown constructor> Bye, Hendrik PS. These two conversions are new, but not marked as such in the enhanced reference manual, because they do not appear in the txt version (which I used for the diffs).