1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
27 * implementazione del comando INTERSECT
31 * eccezione sollevata quando il join dei contesti
34 exception Join_must_be_empty;;
37 * join fra due contesti
39 let xres_join_context h1 l1 h2 l2 =
44 let hh = h2 @ (List.find_all (function t -> not (List.mem t h2)) h1)
45 and m1 = List.combine h1 l1
46 and m2 = List.combine h2 l2
51 let value1 = try (List.assoc elem m1) with Not_found -> List.assoc elem m2
52 and value2 = try (List.assoc elem m2) with Not_found -> List.assoc elem m1
54 if value1 = value2 then value1 else raise Join_must_be_empty
58 Join_must_be_empty -> []
62 * implementazione del comando INTERSECT
64 let intersect_ex alist1 alist2 =
65 let head1 = List.hd alist1
66 and tail1 = List.tl alist1
67 and head2 = List.hd alist2
68 and tail2 = List.tl alist2 (* e fin qui ... *)
70 match (head1, head2) with
71 ([], _) -> assert false (* gli header non devono mai essere vuoti *)
72 | (_, []) -> assert false (* devono contenere almeno [retVal] *)
74 (match (tail1, tail2) with
75 ([], _) -> [["retVal"]] (* se una delle due code e' vuota... *)
76 | (_, []) -> [["retVal"]] (* ... l'intersezione e' vuota *)
80 (function t -> not (List.mem t head2))
83 ] (* header del risultato finale *)
86 (fun par1 elem1 -> par1 @
90 (xres_join_context (List.tl head1) (List.tl elem1)
91 (List.tl head2) (List.tl elem2))
94 (fun elem2 -> (* trova tutti gli elementi della lista tail2 *)
95 ((List.hd elem1) = (List.hd elem2)) && (* che stanno in tail1 *)
96 not ((xres_join_context (List.tl head1) (List.tl elem1)
97 (List.tl head2) (List.tl elem2)) = [])
98 (* e per i quali la xres_join_context non sia vuota *)
104 tail1 (* per ogni elemento di tail1 applica la List.fold_left *)