Commit 177fdd3d authored by bguillaum's avatar bguillaum

iteri and mapi are in the ocaml standard library

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8794 7838e531-6607-4d57-9587-6c381814729c
parent c3d13fb8
......@@ -226,7 +226,7 @@ module List_ = struct
| x::t when x=elt -> t
| x::t -> x::(rm elt t)
let pos x l =
let index x l =
let rec loop i = function
| [] -> None
| h::t when h=x -> Some i
......@@ -258,18 +258,6 @@ module List_ = struct
| [] -> []
| x::t -> (f x)@(flat_map f t)
let iteri fct =
let rec loop i = function
| [] -> ()
| h::t -> (fct i h); (loop (i+1) t) in
loop 0
let mapi fct =
let rec loop i = function
| [] -> []
| h::t -> let head = fct i h in head :: (loop (i+1) t)
in loop 0
let opt_mapi fct =
let rec loop i = function
| [] -> []
......
......@@ -111,9 +111,9 @@ module List_: sig
val set: int -> 'a -> 'a list -> 'a list
(** [pos elt list] return [Some index] if [index] is the smallest position in the [list] equals to [elt].
(** [index elt list] return [Some index] if [index] is the smallest position in the [list] equals to [elt].
None is returned if [elt] is not in the [list] *)
val pos: 'a -> 'a list -> int option
val index: 'a -> 'a list -> int option
val opt_map: ('a -> 'b option) -> 'a list -> 'b list
......@@ -132,10 +132,6 @@ module List_: sig
val to_string: ('a -> string) -> string -> 'a list -> string
val iteri: (int -> 'a -> unit) -> 'a list -> unit
val mapi: (int -> 'a -> 'b) -> 'a list -> 'b list
val sort_mem: 'a -> 'a list -> bool
(* Insert an element in a sorted list. *)
......
......@@ -185,7 +185,7 @@ module Command = struct
match param with
| None -> Error.build ~loc "Unknown command variable '%s'" var
| Some (par,cmd) ->
match (List_.pos var par, List_.pos var cmd) with
match (List_.index var par, List_.index var cmd) with
| (_,Some index) -> Param_out index
| (Some index,_) -> Param_in index
| _ -> Error.build ~loc "Unknown command variable '%s'" var
......
......@@ -134,7 +134,7 @@ module P_feature = struct
match pat_vars with
| None -> Error.bug ~loc "[P_feature.build] param '%s' in an unparametrized rule" var
| Some l ->
match List_.pos var l with
match List_.index var l with
| Some index -> (name, {cst=Different []; in_param = [index]})
| None -> Error.build ~loc "[P_feature.build] Unknown pattern variable '%s'" var
end
......
......@@ -375,7 +375,7 @@ module G_graph = struct
(** input : "Le/DET/le petit/ADJ/petit chat/NC/chat dort/V/dormir ./PONCT/." *)
let of_brown ?sentid brown =
let units = Str.split (Str.regexp " ") brown in
let conll_lines = List_.mapi
let conll_lines = List.mapi
(fun i item -> match Str.full_split (Str.regexp "/[A-Z'+'']+/") item with
| [Str.Text phon; Str.Delim pos; Str.Text lemma] ->
let pos = String.sub pos 1 ((String.length pos)-2) in
......@@ -796,7 +796,7 @@ module G_graph = struct
let snodes = List.sort (fun (_,n1) (_,n2) -> G_node.position_comp n1 n2) nodes in
(* renumbering of nodes to have a consecutive sequence of int 1 --> n, in case of node deletion or addition *)
let snodes = List_.mapi
let snodes = List.mapi
(fun i (gid,node) -> (gid, G_node.set_position (float i) node)
) snodes in
......
......@@ -61,14 +61,14 @@ module Rewrite_history = struct
let rec loop file_name t =
match (t.good_nf, t.bad_nf) with
| [],[] -> File.write (Instance.to_gr t.instance) (file_name^".gr")
| l, _ -> List_.iteri (fun i son -> loop (sprintf "%s_%d" file_name i) son) l
| l, _ -> List.iteri (fun i son -> loop (sprintf "%s_%d" file_name i) son) l
in loop base t
let save_conll base t =
let rec loop file_name t =
match (t.good_nf, t.bad_nf) with
| [],[] -> File.write (Instance.to_conll t.instance) (file_name^".conll")
| l, _ -> List_.iteri (fun i son -> loop (sprintf "%s_%d" file_name i) son) l
| l, _ -> List.iteri (fun i son -> loop (sprintf "%s_%d" file_name i) son) l
in loop base t
let save_full_conll base t =
......@@ -91,7 +91,7 @@ module Rewrite_history = struct
in loop t
let save_annot out_dir base_name t =
List_.mapi
List.mapi
(fun i alts ->
match alts.good_nf with
| [alt_1; alt_2] ->
......
......@@ -578,7 +578,7 @@ module Html_rh = struct
wnl "<div width=100%% style=\"overflow-x:auto\"><IMG SRC=\"%s.png\"></div>" local
end;
List_.iteri
List.iteri
(fun i (rules_list,file_name) ->
wnl "<h6>Solution %d</h6>" (i+1);
......
......@@ -248,7 +248,7 @@ module Rule = struct
(fun (_, dep_line) -> bprintf buff "%s\n" dep_line
) sorted_nodes;
List_.iteri
List.iteri
(fun i cst ->
match cst with
| Cst_out _ | Cst_in _ -> bprintf buff " C_%d { word=\"*\"}\n" i
......@@ -270,7 +270,7 @@ module Rule = struct
(P_node.get_next node)
) pos_basic.graph;
List_.iteri
List.iteri
(fun i cst ->
match cst with
| Cst_out (pid, label_cst) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment