3 * implementazione del comando UNION
9 let xres_fill_context hr h1 l1 =
13 let hh = List.combine h1 l1
17 if (List.mem_assoc x hh) then
26 * implementazione del comando UNION
28 let union_ex alist1 alist2 =
29 let head1 = List.hd alist1
30 and tail1 = List.tl alist1
31 and head2 = List.hd alist2
32 and tail2 = List.tl alist2 (* e fin qui ... *)
34 match (head1, head2) with
35 ([], _) -> assert false (* gli header non devono mai essere vuoti *)
36 | (_, []) -> assert false (* devono contenere almeno [retVal] *)
37 | (_, _) -> let headr = (head2 @
39 (function t -> not (List.mem t head2))
41 ) in (* header del risultato finale *)
42 List.append (* il risultato finale e' la concatenazione ...*)
43 [headr] (* ... dell'header costruito prima ...*)
44 (match (tail1, tail2) with (* e di una coda "unione" *)
45 ([], _) -> tail2 (* va bene perche' l'altra lista e' vuota *)
46 | (_, []) -> tail1 (* va bene perche' l'altra lista e' vuota *)
48 let first = (* parte dell'unione che riguarda solo il primo set *)
49 List.map (fun l -> [List.hd l] @
51 (List.tl headr) (List.tl head1) (List.tl l)
56 let y = (* elemento candidato ad entrare *)
60 (List.tl headr) (List.tl head2) (List.tl x)
62 par @ if (List.find_all (fun t -> t = y) par) = [] then
70 List.map (fun l -> [List.hd l] @
72 (List.tl headr) (List.tl head2) (List.tl l)
81 let h1 = ["retVal"; "a"; "b"];;
82 let l1 = ["pippo"; "3"; "3"];;
83 let l3 = ["pluto"; "7"; "8"]
84 let r1 = [h1; l1; l3];;
86 (*let h2 = ["retVal"; "b"; "c"];;
87 let l2 = ["pippo"; "3"; "1"];;*)
88 let h2 = ["retVal"; "a"; "b"];;
89 let l2 = ["pippo"; "3"; "3"];;
92 List.map (fun l -> List.iter print_endline l) (xres_union (r1, r2));;