Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] printf format strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi Vanicat <remi.vanicat@g...>
Subject: [Caml-list] printf format strings
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.