From b2d85dc2b14c7006280f328e62668c9ec4aa5a43 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Tue, 4 Feb 2003 12:17:02 +0000 Subject: [PATCH] print_endline ==> prerr_endline and other minor code improvements --- helm/ocaml/mathql_interpreter/context.ml | 14 +++----- helm/ocaml/mathql_interpreter/diff.ml | 2 +- helm/ocaml/mathql_interpreter/mqint.ml | 43 +++++++++++++----------- helm/ocaml/mathql_interpreter/select.ml | 10 +++--- helm/ocaml/mathql_interpreter/utility.ml | 2 +- 5 files changed, 35 insertions(+), 36 deletions(-) diff --git a/helm/ocaml/mathql_interpreter/context.ml b/helm/ocaml/mathql_interpreter/context.ml index c9431d1af..377670d18 100644 --- a/helm/ocaml/mathql_interpreter/context.ml +++ b/helm/ocaml/mathql_interpreter/context.ml @@ -15,16 +15,10 @@ type context = {svars: svar_context; (* contesto delle svar *) vvars: vvar_context (* contesto delle vvar introdotte con let-in *) } -let upd_svars c s = - {svars = s; rvars = c.rvars; groups = c.groups; vvars = c.vvars} +let upd_svars c s = {c with svars = s} -let upd_rvars c s = - {svars = c.svars; rvars = s; groups = c.groups; vvars = c.vvars} +let upd_rvars c s = {c with rvars = s} -let upd_groups c s = - {svars = c.svars; rvars = c.rvars; groups = s; vvars = c.vvars} +let upd_groups c s = {c with groups = s} -let upd_vvars c s = - {svars = c.svars; rvars = c.rvars; groups = c.groups; vvars = s} - - +let upd_vvars c s = {c with vvars = s} diff --git a/helm/ocaml/mathql_interpreter/diff.ml b/helm/ocaml/mathql_interpreter/diff.ml index 5cba32345..d52252691 100644 --- a/helm/ocaml/mathql_interpreter/diff.ml +++ b/helm/ocaml/mathql_interpreter/diff.ml @@ -89,7 +89,7 @@ let diff_ex l1 l2 = let ll1 = string_of_int (List.length l1) in let ll2 = string_of_int (List.length l2) in let diff = string_of_float (after -. before) in - print_endline + prerr_endline ("DIFF(" ^ ll1 ^ ", " ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^ ": " ^ diff ^ "s") ; flush stdout ; diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index b275de355..5755aa3a6 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -103,7 +103,7 @@ let rec exec_set_exp c = function let ll2 = string_of_int (List.length rs2) in let diff = string_of_float (after -. before) in if !stat then - (print_endline("INTERSECT(" ^ ll1 ^ "," ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^ + (prerr_endline("INTERSECT(" ^ ll1 ^ "," ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^ ": " ^ diff ^ "s"); flush stdout); res @@ -113,7 +113,7 @@ let rec exec_set_exp c = function let after = Sys.time() in let diff = string_of_float (after -. before) in if !stat then - (print_endline ("UNION: " ^ diff ^ "s"); + (prerr_endline ("UNION: " ^ diff ^ "s"); flush stdout); res | MathQL.LetSVar (svar, sexp1, sexp2) -> @@ -121,8 +121,8 @@ let rec exec_set_exp c = function let c1 = upd_svars c ((svar, exec_set_exp c sexp1) :: c.svars) in let res = exec_set_exp c1 sexp2 in if ! stat then - (print_string ("LETIN " ^ svar ^ " = " ^ string_of_int (List.length res) ^ ": "); - print_endline (string_of_float (Sys.time() -. before) ^ "s"); + (prerr_string ("LETIN " ^ svar ^ " = " ^ string_of_int (List.length res) ^ ": "); + prerr_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res | MathQL.LetVVar (vvar, vexp, sexp) -> @@ -130,8 +130,8 @@ let rec exec_set_exp c = function let c1 = upd_vvars c ((vvar, exec_val_exp c vexp) :: c.vvars) in let res = exec_set_exp c1 sexp in if ! stat then - (print_string ("LETIN " ^ vvar ^ " = " ^ string_of_int (List.length res) ^ ": "); - print_endline (string_of_float (Sys.time() -. before) ^ "s"); + (prerr_string ("LETIN " ^ vvar ^ " = " ^ string_of_int (List.length res) ^ ": "); + prerr_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res | MathQL.Relation (inv, rop, path, sexp, assl) -> @@ -139,16 +139,16 @@ let rec exec_set_exp c = function if ! dbname = postgres_db then (let res = relation_ex inv rop path (exec_set_exp c sexp) assl in if ! stat then - (print_string ("RELATION " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": "); - print_endline (string_of_float (Sys.time() -. before) ^ "s"); + (prerr_string ("RELATION " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": "); + prerr_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res) else (let res = relation_galax_ex inv rop path (exec_set_exp c sexp) assl in if !stat then - (print_string ("RELATION-GALAX " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": "); - print_endline (string_of_float (Sys.time() -. before) ^ "s"); + (prerr_string ("RELATION-GALAX " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": "); + prerr_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res) @@ -156,17 +156,20 @@ let rec exec_set_exp c = function | MathQL.Select (rvar, sexp, bexp) -> let before = Sys.time() in let rset = (exec_set_exp c sexp) in - let rec select_ex rset = - match rset with - [] -> [] - | r::tl -> let c1 = upd_rvars c ((rvar,r)::c.rvars) in - if (exec_boole_exp c1 bexp) then r::(select_ex tl) - else select_ex tl + let rec select_ex = + function + [] -> [] + | r::tl -> + let c1 = upd_rvars c ((rvar,r)::c.rvars) in + if (exec_boole_exp c1 bexp) then + r::(select_ex tl) + else + select_ex tl in let res = select_ex rset in if ! stat then - (print_string ("SELECT " ^ rvar ^ " = " ^ string_of_int (List.length res) ^ ": "); - print_endline (string_of_float (Sys.time() -. before) ^ "s"); + (prerr_string ("SELECT " ^ rvar ^ " = " ^ string_of_int (List.length res) ^ ": "); + prerr_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res | MathQL.Diff (sexp1, sexp2) -> diff_ex (exec_set_exp c sexp1) (exec_set_exp c sexp2) @@ -186,7 +189,9 @@ and exec_boole_exp c = meet_ex (exec_val_exp c vexp1) (exec_val_exp c vexp2) | MathQL.Eq (vexp1, vexp2) -> (exec_val_exp c vexp1) = (exec_val_exp c vexp2) | MathQL.Ex l bexp -> - if l = [] then (exec_boole_exp c bexp) else + if l = [] then + (exec_boole_exp c bexp) + else let latt = List.map (fun uri -> diff --git a/helm/ocaml/mathql_interpreter/select.ml b/helm/ocaml/mathql_interpreter/select.ml index ee9f329ba..a10205490 100644 --- a/helm/ocaml/mathql_interpreter/select.ml +++ b/helm/ocaml/mathql_interpreter/select.ml @@ -92,7 +92,7 @@ let rec is_good env = in let ul1 = set_of_result (None,!execute env q1) in let ul2 = set_of_result (None,!execute env q2) in - print_endline ("MQSETEQUAL(" ^ + prerr_endline ("MQSETEQUAL(" ^ string_of_int (List.length (!execute env q1)) ^ ">" ^ string_of_int (List.length ul1) ^ "," ^ string_of_int (List.length (!execute env q2)) ^ ">" ^ @@ -115,7 +115,7 @@ let rec is_good env = in let ul1 = set_of_result (None,!execute env q1) in let ul2 = set_of_result (None,!execute env q2) in - print_endline ("MQSUBSET(" ^ + prerr_endline ("MQSUBSET(" ^ string_of_int (List.length (!execute env q1)) ^ ">" ^ string_of_int (List.length ul1) ^ "," ^ string_of_int (List.length (!execute env q2)) ^ ">" ^ @@ -138,13 +138,13 @@ let rec is_good env = * implementazione del comando SELECT *) let select_ex env avar alist abool = - let _ = print_string ("SELECT = ") + let _ = prerr_string ("SELECT = ") and t = Sys.time () in let result = List.filter (function entry -> is_good ((avar,entry)::env) abool) alist in - print_string (string_of_int (List.length result) ^ ": ") ; - print_endline (string_of_float (Sys.time () -. t) ^ "s") ; + prerr_string (string_of_int (List.length result) ^ ": ") ; + prerr_endline (string_of_float (Sys.time () -. t) ^ "s") ; flush stdout ; result ;; *) diff --git a/helm/ocaml/mathql_interpreter/utility.ml b/helm/ocaml/mathql_interpreter/utility.ml index 5ea9b7e67..c749f951b 100644 --- a/helm/ocaml/mathql_interpreter/utility.ml +++ b/helm/ocaml/mathql_interpreter/utility.ml @@ -101,7 +101,7 @@ let helm_property_id p = let ns = pgresult_to_string (c#exec q1) in let q2 = ("select att0 from property where att2='" ^ p ^ "' and att1=" ^ ns) in let retval = pgresult_to_string (c#exec q2) in - (*let _ = print_endline ("utility:q2: " ^ q2 ^ " : " ^ retval) in*) + (*let _ = prerr_endline ("utility:q2: " ^ q2 ^ " : " ^ retval) in*) retval ;; -- 2.39.2