Squashed 'sequence/' changes from 0d721a6..2691bee

2691bee version 0.5.3
a373739 merge from master
9fc9a31 bugfix: using the same ExitSequence exception in take and is_empty cannot work
a193c54 added a regression test

git-subtree-dir: sequence
git-subtree-split: 2691bee2f68b7c27a1d1360999d0c21026f77ca9
This commit is contained in:
Simon Cruanes 2014-10-19 21:01:44 +02:00
parent 15665761b2
commit 8bb78ab0d6
6 changed files with 51 additions and 29 deletions

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.5.3
- bugfix: interaction between `take` and `is_empty`
## 0.5.2 ## 0.5.2
- bugfix in `take` - bugfix in `take`

6
META
View file

@ -1,6 +1,6 @@
# OASIS_START # OASIS_START
# DO NOT EDIT (digest: f4f3ee8dc8cda763af26a927b88956e6) # DO NOT EDIT (digest: 99194977427ba82f5912e81125f6cac0)
version = "0.5.2" version = "0.5.3"
description = "Simple sequence (iterator) datatype and combinators" description = "Simple sequence (iterator) datatype and combinators"
archive(byte) = "sequence.cma" archive(byte) = "sequence.cma"
archive(byte, plugin) = "sequence.cma" archive(byte, plugin) = "sequence.cma"
@ -8,7 +8,7 @@ archive(native) = "sequence.cmxa"
archive(native, plugin) = "sequence.cmxs" archive(native, plugin) = "sequence.cmxs"
exists_if = "sequence.cma" exists_if = "sequence.cma"
package "invert" ( package "invert" (
version = "0.5.2" version = "0.5.3"
description = "Simple sequence (iterator) datatype and combinators" description = "Simple sequence (iterator) datatype and combinators"
requires = "sequence delimcc" requires = "sequence delimcc"
archive(byte) = "invert.cma" archive(byte) = "invert.cma"

4
_oasis
View file

@ -1,6 +1,6 @@
OASISFormat: 0.4 OASISFormat: 0.4
Name: sequence Name: sequence
Version: 0.5.2 Version: 0.5.3
Homepage: https://github.com/c-cube/sequence Homepage: https://github.com/c-cube/sequence
Authors: Simon Cruanes Authors: Simon Cruanes
License: BSD-2-clause License: BSD-2-clause
@ -45,7 +45,7 @@ Document sequence
XOCamlbuildLibraries: sequence XOCamlbuildLibraries: sequence
Test all Test all
Type: custom Type: custom (0.4)
Command: make run-tests Command: make run-tests
TestTools: run_tests TestTools: run_tests
Run$: flag(tests) Run$: flag(tests)

View file

@ -319,33 +319,37 @@ let min ?(lt=fun x y -> x < y) seq =
| Some y -> if lt x y then ret := Some x); | Some y -> if lt x y then ret := Some x);
!ret !ret
exception ExitSequence exception ExitHead
let head seq = let head seq =
let r = ref None in let r = ref None in
try try
seq (fun x -> r := Some x; raise ExitSequence); None seq (fun x -> r := Some x; raise ExitHead); None
with ExitSequence -> !r with ExitHead -> !r
let head_exn seq = let head_exn seq =
match head seq with match head seq with
| None -> invalid_arg "Sequence.head_exn" | None -> invalid_arg "Sequence.head_exn"
| Some x -> x | Some x -> x
exception ExitTake
let take n seq k = let take n seq k =
let count = ref 0 in let count = ref 0 in
try try
seq (fun x -> seq (fun x ->
if !count = n then raise ExitSequence; if !count = n then raise ExitTake;
incr count; incr count;
k x; k x;
) )
with ExitSequence -> () with ExitTake -> ()
exception ExitTakeWhile
let take_while p seq k = let take_while p seq k =
try try
seq (fun x -> if p x then k x else raise ExitSequence) seq (fun x -> if p x then k x else raise ExitTakeWhile)
with ExitSequence -> () with ExitTakeWhile -> ()
let drop n seq k = let drop n seq k =
let count = ref 0 in let count = ref 0 in
@ -362,29 +366,35 @@ let rev seq =
let l = MList.of_seq seq in let l = MList.of_seq seq in
fun k -> MList.iter_rev k l fun k -> MList.iter_rev k l
exception ExitForall
let for_all p seq = let for_all p seq =
try try
seq (fun x -> if not (p x) then raise ExitSequence); seq (fun x -> if not (p x) then raise ExitForall);
true true
with ExitSequence -> false with ExitForall -> false
exception ExitExists
(** Exists there some element satisfying the predicate? *) (** Exists there some element satisfying the predicate? *)
let exists p seq = let exists p seq =
try try
seq (fun x -> if p x then raise ExitSequence); seq (fun x -> if p x then raise ExitExists);
false false
with ExitSequence -> true with ExitExists -> true
let mem ?(eq=(=)) x seq = exists (eq x) seq let mem ?(eq=(=)) x seq = exists (eq x) seq
exception ExitFind
let find f seq = let find f seq =
let r = ref None in let r = ref None in
begin try begin try
seq (fun x -> match f x with seq (fun x -> match f x with
| None -> () | None -> ()
| Some _ as res -> r := res | Some _ as res -> r := res; raise ExitFind
); );
with ExitSequence -> () with ExitFind -> ()
end; end;
!r !r
@ -393,17 +403,19 @@ let length seq =
seq (fun _ -> incr r); seq (fun _ -> incr r);
!r !r
exception ExitIsEmpty
let is_empty seq = let is_empty seq =
try seq (fun _ -> raise ExitSequence); true try seq (fun _ -> raise ExitIsEmpty); true
with ExitSequence -> false with ExitIsEmpty -> false
(** {2 Transform a sequence} *) (** {2 Transform a sequence} *)
let empty2 k = () let empty2 k = ()
let is_empty2 seq2 = let is_empty2 seq2 =
try ignore (seq2 (fun _ _ -> raise ExitSequence)); true try ignore (seq2 (fun _ _ -> raise ExitIsEmpty)); true
with ExitSequence -> false with ExitIsEmpty -> false
let length2 seq2 = let length2 seq2 =
let r = ref 0 in let r = ref 0 in

View file

@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.4.4 *) (* setup.ml generated for the first time by OASIS v0.4.4 *)
(* OASIS_START *) (* OASIS_START *)
(* DO NOT EDIT (digest: 3e1599f233d66e02cd17bbb3a1c71d9e) *) (* DO NOT EDIT (digest: 1c260750474eb19b8e9212954217b6fd) *)
(* (*
Regenerated by OASIS v0.4.4 Regenerated by OASIS v0.4.4
Visit http://oasis.forge.ocamlcore.org for more information and Visit http://oasis.forge.ocamlcore.org for more information and
@ -6826,7 +6826,7 @@ let setup_t =
alpha_features = []; alpha_features = [];
beta_features = []; beta_features = [];
name = "sequence"; name = "sequence";
version = "0.5.2"; version = "0.5.3";
license = license =
OASISLicense.DEP5License OASISLicense.DEP5License
(OASISLicense.DEP5Unit (OASISLicense.DEP5Unit
@ -7044,7 +7044,7 @@ let setup_t =
cs_plugin_data = [] cs_plugin_data = []
}, },
{ {
test_type = (`Test, "custom", None); test_type = (`Test, "custom", Some "0.4");
test_command = test_command =
[(OASISExpr.EBool true, ("make", ["run-tests"]))]; [(OASISExpr.EBool true, ("make", ["run-tests"]))];
test_custom = test_custom =
@ -7192,8 +7192,7 @@ let setup_t =
}; };
oasis_fn = Some "_oasis"; oasis_fn = Some "_oasis";
oasis_version = "0.4.4"; oasis_version = "0.4.4";
oasis_digest = oasis_digest = Some "\214\tqh\b\169>\243\237\213\012\180\162\155`L";
Some "\142\243\242-\024\139\245\030\1867\186\147D\175\251\192";
oasis_exec = None; oasis_exec = None;
oasis_setup_args = []; oasis_setup_args = [];
setup_update = false setup_update = false
@ -7201,6 +7200,6 @@ let setup_t =
let setup () = BaseSetup.setup setup_t;; let setup () = BaseSetup.setup setup_t;;
# 7205 "setup.ml" # 7204 "setup.ml"
(* OASIS_STOP *) (* OASIS_STOP *)
let () = setup ();; let () = setup ();;

View file

@ -6,7 +6,8 @@ open Sequence.Infix
let pp_ilist l = let pp_ilist l =
let b = Buffer.create 15 in let b = Buffer.create 15 in
Format.bprintf b "@[<h>%a@]" (S.pp_seq Format.pp_print_int) (S.of_list l); let fmt = Format.formatter_of_buffer b in
Format.fprintf fmt "@[<h>%a@]" (S.pp_seq Format.pp_print_int) (S.of_list l);
Buffer.contents b Buffer.contents b
let test_empty () = let test_empty () =
@ -197,6 +198,11 @@ let test_take () =
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l; OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l;
() ()
let test_regression1 () =
let s = S.(take 10 (repeat 1)) in
OUnit.assert_bool "not empty" (not (S.is_empty s));
()
let suite = let suite =
"test_sequence" >::: "test_sequence" >:::
[ "test_empty" >:: test_empty; [ "test_empty" >:: test_empty;
@ -225,4 +231,5 @@ let suite =
"test_hashtbl" >:: test_hashtbl; "test_hashtbl" >:: test_hashtbl;
"test_int_range" >:: test_int_range; "test_int_range" >:: test_int_range;
"test_take" >:: test_take; "test_take" >:: test_take;
"test_regression1" >:: test_regression1
] ]