mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
rename print to pp for Format printers (closes #153)
This commit is contained in:
parent
19b2b7c7cc
commit
fc329fa118
22 changed files with 50 additions and 42 deletions
|
|
@ -124,7 +124,7 @@ module Poly = struct
|
||||||
()
|
()
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let print pp_k pp_v fmt m =
|
let pp pp_k pp_v fmt m =
|
||||||
Format.fprintf fmt "@[<hov2>tbl {@,";
|
Format.fprintf fmt "@[<hov2>tbl {@,";
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
Hashtbl.iter
|
Hashtbl.iter
|
||||||
|
|
@ -232,9 +232,10 @@ module type S = sig
|
||||||
to [tbl] and [v] is returned.
|
to [tbl] and [v] is returned.
|
||||||
@since 1.0 *)
|
@since 1.0 *)
|
||||||
|
|
||||||
val print : key printer -> 'a printer -> 'a t printer
|
val pp : key printer -> 'a printer -> 'a t printer
|
||||||
(** Printer for tables
|
(** Printer for table
|
||||||
@since 0.13 *)
|
@since 0.13
|
||||||
|
Renamed from [print] @since NEXT_RELEASE *)
|
||||||
end
|
end
|
||||||
|
|
||||||
(*$inject
|
(*$inject
|
||||||
|
|
@ -344,7 +345,7 @@ module Make(X : Hashtbl.HashedType)
|
||||||
List.iter (fun (k,v) -> add tbl k v) l;
|
List.iter (fun (k,v) -> add tbl k v) l;
|
||||||
tbl
|
tbl
|
||||||
|
|
||||||
let print pp_k pp_v fmt m =
|
let pp pp_k pp_v fmt m =
|
||||||
Format.fprintf fmt "@[<hov2>tbl {@,";
|
Format.fprintf fmt "@[<hov2>tbl {@,";
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
iter
|
iter
|
||||||
|
|
|
||||||
|
|
@ -102,9 +102,10 @@ module Poly : sig
|
||||||
to [tbl] and [v] is returned.
|
to [tbl] and [v] is returned.
|
||||||
@since 1.0 *)
|
@since 1.0 *)
|
||||||
|
|
||||||
val print : 'a printer -> 'b printer -> ('a, 'b) Hashtbl.t printer
|
val pp : 'a printer -> 'b printer -> ('a, 'b) Hashtbl.t printer
|
||||||
(** Printer for table
|
(** Printer for table
|
||||||
@since 0.13 *)
|
@since 0.13
|
||||||
|
Renamed from [print] @since NEXT_RELEASE *)
|
||||||
end
|
end
|
||||||
|
|
||||||
include module type of Poly
|
include module type of Poly
|
||||||
|
|
@ -201,9 +202,10 @@ module type S = sig
|
||||||
to [tbl] and [v] is returned.
|
to [tbl] and [v] is returned.
|
||||||
@since 1.0 *)
|
@since 1.0 *)
|
||||||
|
|
||||||
val print : key printer -> 'a printer -> 'a t printer
|
val pp : key printer -> 'a printer -> 'a t printer
|
||||||
(** Printer for tables
|
(** Printer for tables
|
||||||
@since 0.13 *)
|
@since 0.13
|
||||||
|
Renamed from {!print} @since NEXT_RELEASE *)
|
||||||
end
|
end
|
||||||
|
|
||||||
module Make(X : Hashtbl.HashedType) :
|
module Make(X : Hashtbl.HashedType) :
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ module type S = sig
|
||||||
val to_klist : t -> char klist
|
val to_klist : t -> char klist
|
||||||
val to_list : t -> char list
|
val to_list : t -> char list
|
||||||
|
|
||||||
val pp : Buffer.t -> t -> unit
|
val pp_buf : Buffer.t -> t -> unit
|
||||||
val print : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
end
|
end
|
||||||
|
|
||||||
let equal (a:string) b = Pervasives.(=) a b
|
let equal (a:string) b = Pervasives.(=) a b
|
||||||
|
|
@ -783,12 +783,12 @@ let equal_caseless s1 s2: bool =
|
||||||
(fun c1 c2 -> CCChar.equal (CCChar.lowercase_ascii c1) (CCChar.lowercase_ascii c2))
|
(fun c1 c2 -> CCChar.equal (CCChar.lowercase_ascii c1) (CCChar.lowercase_ascii c2))
|
||||||
s1 s2
|
s1 s2
|
||||||
|
|
||||||
let pp buf s =
|
let pp_buf buf s =
|
||||||
Buffer.add_char buf '"';
|
Buffer.add_char buf '"';
|
||||||
Buffer.add_string buf s;
|
Buffer.add_string buf s;
|
||||||
Buffer.add_char buf '"'
|
Buffer.add_char buf '"'
|
||||||
|
|
||||||
let print fmt s =
|
let pp fmt s =
|
||||||
Format.fprintf fmt "\"%s\"" s
|
Format.fprintf fmt "\"%s\"" s
|
||||||
|
|
||||||
module Sub = struct
|
module Sub = struct
|
||||||
|
|
@ -830,11 +830,11 @@ module Sub = struct
|
||||||
let to_klist (s,i,len) = _to_klist s i len
|
let to_klist (s,i,len) = _to_klist s i len
|
||||||
let to_list (s,i,len) = _to_list s [] i len
|
let to_list (s,i,len) = _to_list s [] i len
|
||||||
|
|
||||||
let pp buf (s,i,len) =
|
let pp_buf buf (s,i,len) =
|
||||||
Buffer.add_char buf '"';
|
Buffer.add_char buf '"';
|
||||||
Buffer.add_substring buf s i len;
|
Buffer.add_substring buf s i len;
|
||||||
Buffer.add_char buf '"'
|
Buffer.add_char buf '"'
|
||||||
|
|
||||||
let print fmt s =
|
let pp fmt s =
|
||||||
Format.fprintf fmt "\"%s\"" (copy s)
|
Format.fprintf fmt "\"%s\"" (copy s)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,12 @@ module type S = sig
|
||||||
val to_klist : t -> char klist
|
val to_klist : t -> char klist
|
||||||
val to_list : t -> char list
|
val to_list : t -> char list
|
||||||
|
|
||||||
val pp : Buffer.t -> t -> unit
|
val pp_buf : Buffer.t -> t -> unit
|
||||||
val print : Format.formatter -> t -> unit
|
(** Renamed from [pp] @since NEXT_RELEASE *)
|
||||||
(** Print the string within quotes *)
|
|
||||||
|
val pp : Format.formatter -> t -> unit
|
||||||
|
(** Print the string within quotes
|
||||||
|
Renamed from [print] @since NEXT_RELEASE *)
|
||||||
end
|
end
|
||||||
|
|
||||||
(** {2 Strings} *)
|
(** {2 Strings} *)
|
||||||
|
|
@ -718,7 +721,7 @@ module Sub : sig
|
||||||
|
|
||||||
(*$T
|
(*$T
|
||||||
let sub = Sub.make " abc " 1 ~len:3 in \
|
let sub = Sub.make " abc " 1 ~len:3 in \
|
||||||
"\"abc\"" = (CCFormat.to_string Sub.print sub)
|
"\"abc\"" = (CCFormat.to_string Sub.pp sub)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(*$= & ~printer:(String.make 1)
|
(*$= & ~printer:(String.make 1)
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ let of_seq seq =
|
||||||
|> CCList.of_seq |> List.sort CCOrd.compare = CCList.range 0 10
|
|> CCList.of_seq |> List.sort CCOrd.compare = CCList.range 0 10
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let print out bv =
|
let pp out bv =
|
||||||
Format.pp_print_string out "bv {";
|
Format.pp_print_string out "bv {";
|
||||||
iter bv
|
iter bv
|
||||||
(fun _i b ->
|
(fun _i b ->
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,6 @@ type 'a sequence = ('a -> unit) -> unit
|
||||||
val to_seq : t -> int sequence
|
val to_seq : t -> int sequence
|
||||||
val of_seq : int sequence -> t
|
val of_seq : int sequence -> t
|
||||||
|
|
||||||
val print : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
(** Print the bitvector as a string of bits
|
(** Print the bitvector as a string of bits
|
||||||
@since 0.13 *)
|
@since 0.13 *)
|
||||||
|
|
|
||||||
|
|
@ -405,7 +405,7 @@ let compare ~cmp a b =
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
let print pp_x out d =
|
let pp pp_x out d =
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
Format.fprintf out "@[<hov2>deque {";
|
Format.fprintf out "@[<hov2>deque {";
|
||||||
iter
|
iter
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,6 @@ val to_rev_list : 'a t -> 'a list
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val print : 'a printer -> 'a t printer
|
val pp : 'a printer -> 'a t printer
|
||||||
(** Print the elements
|
(** Print the elements
|
||||||
@since 0.13 *)
|
@since 0.13 *)
|
||||||
|
|
|
||||||
|
|
@ -515,7 +515,7 @@ let (--^) a b =
|
||||||
0 --^ 0 |> to_list = []
|
0 --^ 0 |> to_list = []
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let print pp_x out d =
|
let pp pp_x out d =
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
Format.fprintf out "@[<hov2>queue {";
|
Format.fprintf out "@[<hov2>queue {";
|
||||||
iter
|
iter
|
||||||
|
|
|
||||||
|
|
@ -135,5 +135,5 @@ val (--^) : int -> int -> int t
|
||||||
(** [a -- b] is the integer range from [a] to [b], where [b] is excluded.
|
(** [a -- b] is the integer range from [a] to [b], where [b] is excluded.
|
||||||
@since 0.17 *)
|
@since 0.17 *)
|
||||||
|
|
||||||
val print : 'a printer -> 'a t printer
|
val pp : 'a printer -> 'a t printer
|
||||||
(** @since 0.13 *)
|
(** @since 0.13 *)
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ module type S = sig
|
||||||
|
|
||||||
(** {6 IO} *)
|
(** {6 IO} *)
|
||||||
|
|
||||||
val print : key printer -> 'a printer -> 'a t printer
|
val pp : key printer -> 'a printer -> 'a t printer
|
||||||
|
|
||||||
val as_tree : 'a t -> [`L of int * (key * 'a) list | `N ] ktree
|
val as_tree : 'a t -> [`L of int * (key * 'a) list | `N ] ktree
|
||||||
(** For debugging purpose: explore the structure of the tree,
|
(** For debugging purpose: explore the structure of the tree,
|
||||||
|
|
@ -698,7 +698,7 @@ module Make(Key : KEY)
|
||||||
| None -> raise Not_found
|
| None -> raise Not_found
|
||||||
| Some (k,v) -> k, v
|
| Some (k,v) -> k, v
|
||||||
|
|
||||||
let print ppk ppv out m =
|
let pp ppk ppv out m =
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
iter m
|
iter m
|
||||||
~f:(fun k v ->
|
~f:(fun k v ->
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,8 @@ module type S = sig
|
||||||
|
|
||||||
(** {6 IO} *)
|
(** {6 IO} *)
|
||||||
|
|
||||||
val print : key printer -> 'a printer -> 'a t printer
|
val pp : key printer -> 'a printer -> 'a t printer
|
||||||
|
(** Renamed from [val print] @since NEXT_RELEASE *)
|
||||||
|
|
||||||
val as_tree : 'a t -> [`L of int * (key * 'a) list | `N ] ktree
|
val as_tree : 'a t -> [`L of int * (key * 'a) list | `N ] ktree
|
||||||
(** For debugging purpose: explore the structure of the tree,
|
(** For debugging purpose: explore the structure of the tree,
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ let to_gen a =
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
let print ?(start="") ?(stop="") ?(sep=", ") pp_item out a =
|
let pp ?(start="") ?(stop="") ?(sep=", ") pp_item out a =
|
||||||
Format.pp_print_string out start;
|
Format.pp_print_string out start;
|
||||||
for k = 0 to Array.length a - 1 do
|
for k = 0 to Array.length a - 1 do
|
||||||
if k > 0 then (
|
if k > 0 then (
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ val to_gen : 'a t -> 'a gen
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val print :
|
val pp :
|
||||||
?start:string -> ?stop:string -> ?sep:string ->
|
?start:string -> ?stop:string -> ?sep:string ->
|
||||||
'a printer -> 'a t printer
|
'a printer -> 'a t printer
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -326,14 +326,14 @@ let rec union f t1 t2 =
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(*$R
|
(*$R
|
||||||
assert_equal ~cmp:(equal ~eq:(=)) ~printer:(CCFormat.to_string (print CCString.print))
|
assert_equal ~cmp:(equal ~eq:(=)) ~printer:(CCFormat.to_string (pp CCString.pp))
|
||||||
(of_list [1, "1"; 2, "2"; 3, "3"; 4, "4"])
|
(of_list [1, "1"; 2, "2"; 3, "3"; 4, "4"])
|
||||||
(union (fun _ a b -> a)
|
(union (fun _ a b -> a)
|
||||||
(of_list [1, "1"; 3, "3"]) (of_list [2, "2"; 4, "4"]));
|
(of_list [1, "1"; 3, "3"]) (of_list [2, "2"; 4, "4"]));
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(*$R
|
(*$R
|
||||||
assert_equal ~cmp:(equal ~eq:(=)) ~printer:(CCFormat.to_string (print CCString.print))
|
assert_equal ~cmp:(equal ~eq:(=)) ~printer:(CCFormat.to_string (pp CCString.pp))
|
||||||
(of_list [1, "1"; 2, "2"; 3, "3"; 4, "4"])
|
(of_list [1, "1"; 2, "2"; 3, "3"; 4, "4"])
|
||||||
(union (fun _ a b -> a)
|
(union (fun _ a b -> a)
|
||||||
(of_list [1, "1"; 2, "2"; 3, "3"]) (of_list [2, "2"; 4, "4"]))
|
(of_list [1, "1"; 2, "2"; 3, "3"]) (of_list [2, "2"; 4, "4"]))
|
||||||
|
|
@ -369,7 +369,7 @@ let rec inter f a b =
|
||||||
else E
|
else E
|
||||||
|
|
||||||
(*$R
|
(*$R
|
||||||
assert_equal ~cmp:(equal ~eq:(=)) ~printer:(CCFormat.to_string (print CCString.print))
|
assert_equal ~cmp:(equal ~eq:(=)) ~printer:(CCFormat.to_string (pp CCString.pp))
|
||||||
(singleton 2 "2")
|
(singleton 2 "2")
|
||||||
(inter (fun _ a b -> a)
|
(inter (fun _ a b -> a)
|
||||||
(of_list [1, "1"; 2, "2"; 3, "3"]) (of_list [2, "2"; 4, "4"]))
|
(of_list [1, "1"; 2, "2"; 3, "3"]) (of_list [2, "2"; 4, "4"]))
|
||||||
|
|
@ -533,7 +533,7 @@ let rec as_tree t () = match t with
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
let print pp_x out m =
|
let pp pp_x out m =
|
||||||
Format.fprintf out "@[<hov2>intmap {@,";
|
Format.fprintf out "@[<hov2>intmap {@,";
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
iter
|
iter
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ val as_tree : 'a t -> [`Node of int * int | `Leaf of int * 'a ] tree
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val print : 'a printer -> 'a t printer
|
val pp : 'a printer -> 'a t printer
|
||||||
(** @since 0.13 *)
|
(** @since 0.13 *)
|
||||||
|
|
||||||
(** Helpers *)
|
(** Helpers *)
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ let to_gen a =
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
let print pp_item out v =
|
let pp pp_item out v =
|
||||||
Format.fprintf out "[|";
|
Format.fprintf out "[|";
|
||||||
iteri
|
iteri
|
||||||
(fun i x ->
|
(fun i x ->
|
||||||
|
|
|
||||||
|
|
@ -131,5 +131,5 @@ val to_gen : 'a t -> 'a gen
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val print : 'a printer -> 'a t printer
|
val pp : 'a printer -> 'a t printer
|
||||||
(** @since 0.13 *)
|
(** @since 0.13 *)
|
||||||
|
|
|
||||||
|
|
@ -576,7 +576,7 @@ include Infix
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
let print ?(sep=", ") pp_item fmt l =
|
let pp ?(sep=", ") pp_item fmt l =
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
iter l
|
iter l
|
||||||
~f:(fun x ->
|
~f:(fun x ->
|
||||||
|
|
|
||||||
|
|
@ -187,4 +187,4 @@ include module type of Infix
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val print : ?sep:string -> 'a printer -> 'a t printer
|
val pp : ?sep:string -> 'a printer -> 'a t printer
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ module type S = sig
|
||||||
|
|
||||||
val to_gen : 'a t -> (key * 'a) gen
|
val to_gen : 'a t -> (key * 'a) gen
|
||||||
|
|
||||||
val print : key printer -> 'a printer -> 'a t printer
|
val pp : key printer -> 'a printer -> 'a t printer
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
val node_ : key -> 'a -> 'a t -> 'a t -> 'a t
|
val node_ : key -> 'a -> 'a t -> 'a t -> 'a t
|
||||||
|
|
@ -588,7 +588,7 @@ module MakeFull(K : KEY) : S with type key = K.t = struct
|
||||||
Some (k,v)
|
Some (k,v)
|
||||||
in next
|
in next
|
||||||
|
|
||||||
let print pp_k pp_v fmt m =
|
let pp pp_k pp_v fmt m =
|
||||||
let start = "[" and stop = "]" and arrow = "->" and sep = ","in
|
let start = "[" and stop = "]" and arrow = "->" and sep = ","in
|
||||||
Format.pp_print_string fmt start;
|
Format.pp_print_string fmt start;
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,8 @@ module type S = sig
|
||||||
|
|
||||||
val to_gen : 'a t -> (key * 'a) gen
|
val to_gen : 'a t -> (key * 'a) gen
|
||||||
|
|
||||||
val print : key printer -> 'a printer -> 'a t printer
|
val pp : key printer -> 'a printer -> 'a t printer
|
||||||
|
(** Renamed from [val print] @since NEXT_RELEASE *)
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
val node_ : key -> 'a -> 'a t -> 'a t -> 'a t
|
val node_ : key -> 'a -> 'a t -> 'a t -> 'a t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue