New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format.bprintf problems #3007
Comments
Comment author: administrator
I'm not sure that the behaviour you observed can be considered a Hence, your message is very interesting since it points out a In the mean time, an easy work-around is NOT to use the bprintf let b = Buffer.create 1024 in Hope this helps, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ |
Comment author: administrator Thank you quick answer. I tried to get rid of this problem by using a Thank you. |
Original bug ID: 606
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Ken Wakita
Version: 3.02 and 3.03 alpha
OS: Linux and Cygwin
Submission from: n8nat-9.is.titech.ac.jp (131.112.50.139)
Format.bprintf does not accept "%a" format: bprintf_list1
fails to type check. It seems that O'Caml's type checker presumes
that the output for the formatter is an output channel.
Then I removed all the use of "%a" and got fprintf_list2 and
bprintf_list2. Both compiles well but the latter ignores all the
formatting directives.
If there is a work-around please let me know.
Ken Wakita
let fprintf p fmt = Format.fprintf p fmt
let bprintf b fmt = Format.bprintf b fmt
let rec fprintf_list1 p = function
| [] -> ()
| [x] -> fprintf p "%d" x
| (x :: l) -> fprintf p "%d@;%a" x fprintf_list1 l
let rec fprintf_list2 p = function
| [] -> ()
| [x] -> fprintf p "%d" x
| (x :: l) -> fprintf p "%d@;" x; fprintf_list2 p l
(*
let rec bprintf_list1 b = function
| [] -> ()
| [x] -> bprintf b "%d" x
| (x :: l) -> bprintf b "%d@;%a" x bprintf_list1 l
*)
let rec bprintf_list2 b = function
| [] -> ()
| [x] -> bprintf b "%d" x
| (x :: l) -> bprintf b "%d@;" x; bprintf_list2 b l
let rec upto n =
Array.to_list (Array.mapi (fun i _ -> i) (Array.make n ()))
let _ =
let p = Format.std_formatter in
fprintf p " @[%a@]@." fprintf_list1 (upto 100);
fprintf p " @[";
fprintf_list2 p (upto 100);
fprintf p "@]@.";
let b = Buffer.create 1024 in
bprintf b " @[";
bprintf_list2 b (upto 100);
bprintf b "@]@.";
print_string (Buffer.contents b)
The text was updated successfully, but these errors were encountered: