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

add IO.scanf #13

Closed
ygrek opened this issue Aug 29, 2015 · 2 comments
Closed

add IO.scanf #13

ygrek opened this issue Aug 29, 2015 · 2 comments

Comments

@ygrek
Copy link
Owner

ygrek commented Aug 29, 2015

Originally reported on Google Code with ID 8

Seems like extlib should include IO.scanf for symmetry with IO.printf:

--- IO.mli.orig 2008-07-13 14:36:59.000000000 -0700
+++ IO.mli  2008-07-13 14:02:02.000000000 -0700
@@ -135,6 +135,9 @@

 (** {6 Utilities} *)

+val scanf : input -> ('a, 'b, 'c, 'd) Scanf.scanner
+(** The scanf function works for any input. *)
+
 val printf : 'a output -> ('b, unit, string, unit) format4 -> 'b
 (** The printf function works for any output. *)

--- IO.ml.orig  2008-07-13 14:36:59.000000000 -0700
+++ IO.ml   2008-07-13 14:06:12.000000000 -0700
@@ -145,6 +145,10 @@
    if p + l > sl || p < 0 || l < 0 then invalid_arg "IO.output";
    o.out_output s p l

+let scanf i fmt =
+   let ib = Scanf.Scanning.from_function (fun () -> read i) in
+   Scanf.kscanf ib (fun _ exn -> raise exn) fmt
+
 let printf o fmt =
    Printf.kprintf (fun s -> nwrite o s) fmt


Reported by warrenharris1 on 2008-07-13 21:38:27

@ygrek
Copy link
Owner Author

ygrek commented Aug 29, 2015

Note that it needs special handling for IO.No_more_input.
Consider :
let io = IO.input_string "hello world";;
IO.scanf io "%s %s" (fun x y -> print_endline x; print_endline y);;

Reported by ygrekheretix on 2013-11-12 16:00:37

@ygrek
Copy link
Owner Author

ygrek commented Aug 29, 2015

This issue was closed by revision r424.

Reported by ygrekheretix on 2013-11-12 16:01:26

  • Status changed: Fixed

@ygrek ygrek closed this as completed Aug 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant