* [Caml-list] printf format strings
@ 2005-11-30 23:31 Jonathan Roewen
2005-12-01 10:18 ` Hendrik Tews
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Roewen @ 2005-11-30 23:31 UTC (permalink / raw)
To: caml-list
Hi,
What is the following for?
{ 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.
Jonathan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] printf format strings
2005-11-30 23:31 [Caml-list] printf format strings Jonathan Roewen
@ 2005-12-01 10:18 ` Hendrik Tews
[not found] ` <6b8a91420512010825k23d78780u@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Hendrik Tews @ 2005-12-01 10:18 UTC (permalink / raw)
To: caml-list
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).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Caml-list] printf format strings
[not found] ` <6b8a91420512010825k23d78780u@mail.gmail.com>
@ 2005-12-01 16:26 ` Remi Vanicat
0 siblings, 0 replies; 3+ messages in thread
From: Remi Vanicat @ 2005-12-01 16:26 UTC (permalink / raw)
To: caml-list
005/12/1, Hendrik Tews <tews@tcs.inf.tu-dresden.de>:
> 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???
Well, I've guessed a bug in the type system, and it seem I'm correct:
let t = Obj.repr (Printf.printf "%{%d%s%}" "kk%dkk%s\n");;
# Obj.is_block t;;
- : bool = true
# Obj.is_block (Obj.repr ());;
- : bool = false
# Obj.tag t;;
- : int = 247
# Obj.closure_tag;;
- : int = 247
So this is a closure, so a function that should have a functional type.
I've tried to play with the devil, and here my result :
# (Obj.magic( Printf.printf "%{%d%s%}" "kk%dkk%s\n") 5 "rae" () : unit );;
%i%s- : unit = ()
Very strange indeed.
Well, this should be reported in the bug tracking system.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-12-01 16:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-30 23:31 [Caml-list] printf format strings Jonathan Roewen
2005-12-01 10:18 ` Hendrik Tews
[not found] ` <6b8a91420512010825k23d78780u@mail.gmail.com>
2005-12-01 16:26 ` Remi Vanicat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox