Skip to content
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 #3006

Closed
vicuna opened this issue Nov 2, 2001 · 1 comment
Closed

Format.bprintf problems #3006

vicuna opened this issue Nov 2, 2001 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 2, 2001

Original bug ID: 605
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)

@vicuna
Copy link
Author

vicuna commented Nov 7, 2001

Comment author: administrator

see #3007

@vicuna vicuna closed this as completed Nov 7, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant