diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1998-04-27 09:55:21 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1998-04-27 09:55:21 +0000 |
commit | 208be2cae2ec48293f30590ba9184f0e813402d2 (patch) | |
tree | 4574c7f0cc42b05e7fda6439ba593c51169f056c /stdlib | |
parent | 655531aa4c34a86f7b07da0238a6b2a617ed7406 (diff) |
Ajout de List.rev_append. Nettoyages
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1932 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/list.ml | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/stdlib/list.ml b/stdlib/list.ml index bd7041961..0d3514c4f 100644 --- a/stdlib/list.ml +++ b/stdlib/list.ml @@ -35,11 +35,14 @@ let rec nth l n = if n > 0 then nth l (n-1) else invalid_arg "List.nth" -let rec rev_append accu = function - [] -> accu - | a::l -> rev_append (a :: accu) l +let append = (@) + +let rec rev_append l1 l2 = + match l1 with + [] -> l2 + | a :: l -> rev_append l (a :: l2) -let rev l = rev_append [] l +let rev l = rev_append l [] let rec flatten = function [] -> [] @@ -91,31 +94,31 @@ let rec fold_right2 f l1 l2 accu = let rec for_all p = function [] -> true - | a::l -> p a & for_all p l + | a::l -> p a && for_all p l let rec exists p = function [] -> false - | a::l -> p a or exists p l + | a::l -> p a || exists p l let rec for_all2 p l1 l2 = match (l1, l2) with ([], []) -> true - | (a1::l1, a2::l2) -> p a1 a2 & for_all2 p l1 l2 + | (a1::l1, a2::l2) -> p a1 a2 && for_all2 p l1 l2 | (_, _) -> invalid_arg "List.for_all2" let rec exists2 p l1 l2 = match (l1, l2) with ([], []) -> false - | (a1::l1, a2::l2) -> p a1 a2 or exists2 p l1 l2 + | (a1::l1, a2::l2) -> p a1 a2 || exists2 p l1 l2 | (_, _) -> invalid_arg "List.exists2" let rec mem x = function [] -> false - | a::l -> a = x or mem x l + | a::l -> a = x || mem x l let rec memq x = function [] -> false - | a::l -> a == x or memq x l + | a::l -> a == x || memq x l let rec assoc x = function [] -> raise Not_found @@ -123,7 +126,7 @@ let rec assoc x = function let rec mem_assoc x = function [] -> false - | (a,b)::l -> a = x or mem_assoc x l + | (a,b)::l -> a = x || mem_assoc x l let rec assq x = function [] -> raise Not_found |