X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql%2FavsUtil.ml;fp=helm%2Focaml%2Fmathql%2FavsUtil.ml;h=65bcadb15e3c46d8900cd702b7235dfd19610a84;hb=381006cf8b418cfdeaf145ab7df9e8f2b19ae2e6;hp=0000000000000000000000000000000000000000;hpb=efdc3184ccd0738fe48aa0056fc444fba23329e8;p=helm.git diff --git a/helm/ocaml/mathql/avsUtil.ml b/helm/ocaml/mathql/avsUtil.ml new file mode 100644 index 000000000..65bcadb15 --- /dev/null +++ b/helm/ocaml/mathql/avsUtil.ml @@ -0,0 +1,89 @@ +(* Copyright (C) 2000, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://cs.unibo.it/helm/. + *) + +(* AUTOR: Ferruccio Guidi + *) + +module I = MathQL.I + +(* strings ******************************************************************) + +let avs_of_string s = I.make s I.grp_empty + +let string_of_avs r = + match I.peek r with + | I.Single (s, _) -> Some s + | _ -> None + +(* boolean constants *******************************************************) + +let bool_of_avs r = r <> I.empty + +let avs_of_bool = function + | true -> I.make "" I.grp_empty + | false -> I.empty + +let val_false = avs_of_bool false + +let val_true = avs_of_bool true + +(* iterators ****************************************************************) + +let grp_iter f al = + List.fold_left (fun s a -> I.grp_union s (f a)) I.grp_empty al + +let grp_iter2 f al bl = + List.fold_left2 (fun s a b -> I.grp_union s (f a b)) I.grp_empty al bl + +let iter f al = List.fold_left (fun s a -> I.union s (f a)) I.empty al + +let append_iter f al = List.fold_left (fun s a -> I.append (f a) s) I.empty al + +(* other ********************************************************************) + +let grp_make_x p vl = grp_iter (I.grp_make p) vl + +let x_grp_make_x p rs = + let aux g s _ = I.grp_make p s in + I.iter aux I.grp_empty rs + +let make_x s gl = iter (I.make s) gl + +let count v = I.iter (fun n _ _ -> succ n) 0 v + +let subj v = iter (fun s -> I.make s I.grp_empty) v + +(* numeric operations *******************************************************) + +exception NumberError of MathQL.result + +let avs_of_int i = I.make (string_of_int i) I.grp_empty + +let int_of_avs r = + try match (I.peek r) with + | I.Empty + | I.Many _ -> raise (Failure "int_of_string") + | I.Single (s, _) -> MQueryUtil.int_of_string s + with Failure "int_of_string" -> raise (NumberError r)