diff options
| author | letouzey | 2010-04-16 14:13:00 +0000 |
|---|---|---|
| committer | letouzey | 2010-04-16 14:13:00 +0000 |
| commit | e960cd8dac76829f3a48167e70a23c65d8dd797f (patch) | |
| tree | 6a4612192d654046872255f98bacf984da949288 /lib | |
| parent | f57a38bb53dc06cef1cee78c60946aa5e6d3cf0b (diff) | |
Util: remove list_split_at which is a clone of list_chop
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@12939 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/util.ml | 28 | ||||
| -rw-r--r-- | lib/util.mli | 4 |
2 files changed, 13 insertions, 19 deletions
diff --git a/lib/util.ml b/lib/util.ml index a2c6c7899d..ba3d2c6d28 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -396,14 +396,6 @@ let list_subtract l1 l2 = let list_subtractq l1 l2 = if l2 = [] then l1 else List.filter (fun x -> not (List.memq x l2)) l1 -let list_chop n l = - let rec chop_aux acc = function - | (0, l2) -> (List.rev acc, l2) - | (n, (h::t)) -> chop_aux (h::acc) (pred n, t) - | (_, []) -> failwith "list_chop" - in - chop_aux [] (n,l) - let list_tabulate f len = let rec tabrec n = if n = len then [] else (f n)::(tabrec (n+1)) @@ -655,15 +647,17 @@ let list_subset l1 l2 = in look l1 -(* [list_split_at i l] splits [l] into two lists [(l1,l2)] such that [l1++l2=l] - and [l1] has length [i]. - It raises [Failure] when [i] is negative or greater than the length of [l] *) -let list_split_at index l = - let rec aux i acc = function - tl when i = index -> (List.rev acc), tl - | hd :: tl -> aux (succ i) (hd :: acc) tl - | [] -> failwith "list_split_at: Invalid argument" - in aux 0 [] l +(* [list_chop i l] splits [l] into two lists [(l1,l2)] such that + [l1++l2=l] and [l1] has length [i]. + It raises [Failure] when [i] is negative or greater than the length of [l] *) + +let list_chop n l = + let rec chop_aux i acc = function + | tl when i=0 -> (List.rev acc, tl) + | h::t -> chop_aux (pred i) (h::acc) t + | [] -> failwith "list_chop" + in + chop_aux n [] l (* [list_split_when p l] splits [l] into two lists [(l1,a::l2)] such that [l1++(a::l2)=l], [p a=true] and [p b = false] for every element [b] of [l1]. diff --git a/lib/util.mli b/lib/util.mli index ddf32e7623..f900e9bf71 100644 --- a/lib/util.mli +++ b/lib/util.mli @@ -116,7 +116,6 @@ val list_union : 'a list -> 'a list -> 'a list val list_unionq : 'a list -> 'a list -> 'a list val list_subtract : 'a list -> 'a list -> 'a list val list_subtractq : 'a list -> 'a list -> 'a list -val list_chop : int -> 'a list -> 'a list * 'a list (* [list_tabulate f n] builds [[f 0; ...; f (n-1)]] *) val list_tabulate : (int -> 'a) -> int -> 'a list val list_make : int -> 'a -> 'a list @@ -164,7 +163,8 @@ val list_uniquize : 'a list -> 'a list (* merges two sorted lists and preserves the uniqueness property: *) val list_merge_uniq : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list val list_subset : 'a list -> 'a list -> bool -val list_split_at : int -> 'a list -> 'a list*'a list +val list_chop : int -> 'a list -> 'a list * 'a list +(* former [list_split_at] was a duplicate of [list_chop] *) val list_split_when : ('a -> bool) -> 'a list -> 'a list * 'a list val list_split3 : ('a * 'b * 'c) list -> 'a list * 'b list * 'c list val list_partition_by : ('a -> 'a -> bool) -> 'a list -> 'a list list |
