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
50 let value1 = try (List.assoc elem m1) with Not_found -> List.assoc elem m2
51 and value2 = try (List.assoc elem m2) with Not_found -> List.assoc elem m1
53 if value1 = value2 then value1 else raise Join_must_be_empty
61 let intersect_tails h1 t1 h2 t2 =
66 | ((l1::tl1)::tll1, (l2::tl2)::tll2) ->
69 (*match xres_join_context h1 tl1 h2 tl2 with
71 | t ->*) (l1::(xres_join_context h1 tl1 h2 tl2))::(aux tll1 tll2)
73 Join_must_be_empty -> aux tll1 tll2
85 * implementazione del comando INTERSECT
87 let intersect_ex l1 l2 =
89 ((head1::tail1), (head2::tail2)) ->
90 (match (head1, head2) with
91 ([], _) -> assert false (* gli header non devono mai essere vuoti *)
92 | (_, []) -> assert false (* devono contenere almeno [retVal] *)
94 (match (tail1, tail2) with
95 ([], _) -> [["retVal"]] (* se una delle due code e' vuota... *)
96 | (_, []) -> [["retVal"]] (* ... l'intersezione e' vuota *)
100 (function t -> not (List.mem t head2))
103 ] (* header del risultato finale *)
105 intersect_tails (List.tl head1) tail1 (List.tl head2) tail2
108 (fun par1 elem1 -> par1 @
112 (xres_join_context (List.tl head1) (List.tl elem1)
113 (List.tl head2) (List.tl elem2)
117 (fun elem2 -> (* trova tutti gli elementi della lista tail2 *)
118 ((List.hd elem1) = (List.hd elem2)) && (* che stanno in tail1 *)
119 not ((xres_join_context (List.tl head1) (List.tl elem1)
120 (List.tl head2) (List.tl elem2)) = [])
121 (* e per i quali la xres_join_context non sia vuota *)
123 tail2 (* List.find_all *)
127 tail1 (* per ogni elemento di tail1 applica la List.fold_left *)