From f59fa8ab2b6eda5298701bf476da326b795cc17b Mon Sep 17 00:00:00 2001 From: acondolu Date: Wed, 12 Jul 2017 21:48:01 +0200 Subject: [PATCH] Prettier-printing: string_of_problem outputs OCaml code (cherry picked from commit d97b1a852472085bf3449e34f3b25aee349686fd) --- ocaml/lambda4.ml | 28 ++++++++++++++-------------- ocaml/num.ml | 5 ++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/ocaml/lambda4.ml b/ocaml/lambda4.ml index 6c344ac..369e242 100644 --- a/ocaml/lambda4.ml +++ b/ocaml/lambda4.ml @@ -58,21 +58,21 @@ let string_of_measure = string_of_int;; let print_problem label ({freshno; div; conv; ps; deltas} as p) = Console.print_hline (); - prerr_endline ("\n||||| Displaying problem: " ^ label ^ " |||||"); - let nl = "\n| " in - let deltas = String.concat nl (List.map (fun r -> String.concat " <> " (List.map (fun (i,_) -> string_of_int i) !r)) deltas) in + prerr_string ("\n(* DISPLAY PROBLEM (" ^ label ^ ") - "); + let nl = "\n" in + let deltas = String.concat (nl^" ") (List.map (fun r -> String.concat " <> " (List.map (fun (i,_) -> string_of_int i) !r)) deltas) in let l = Array.to_list (Array.init (freshno + 1) string_of_var) in - nl ^ "measure="^string_of_measure(problem_measure p)^" freshno = " ^ string_of_int freshno - ^ nl ^ "\b> DISCRIMINATING SETS (deltas)" - ^ nl ^ deltas ^ (if deltas = "" then "" else nl) - ^ "\b> DIVERGENT" ^ nl - ^ "*: " ^ (match div with None -> "*" | Some div -> print ~l (div :> nf)) ^ "\n| " - ^ "\b> CONVERGENT" ^ nl - ^ String.concat "\n| " (List.map (fun t -> "_: " ^ (if t = `N (-1) then "_" else print ~l (t :> nf))) conv) ^ - (if conv = [] then "" else "\n| ") - ^ "\b> NUMERIC" ^ nl - ^ String.concat "\n| " (List.mapi (fun i t -> string_of_int i ^ ": " ^ print ~l (t :> nf)) ps) - ^ nl + "measure="^string_of_measure(problem_measure p) (* ^ " freshno = " ^ string_of_int freshno*) + ^ nl ^ " Discriminating sets (deltas):" + ^ nl ^ " " ^ deltas ^ (if deltas = " " then "" else nl) ^ "*)" ^ nl + ^" (* DIVERGENT *)" ^ nl + ^" "^ (match div with None -> "None" | Some div -> "(Some\""^ print ~l (div :> nf) ^"\" ") ^ nl + ^" (* CONVERGENT *) [" ^ nl + ^ String.concat "\n " (List.map (fun t -> "(* _: *) " ^ (if t = `N (-1) then "" else "\""^ print ~l (t :> nf) ^"\";")) conv) ^ + (if conv = [] then "" else nl) + ^ "] (* NUMERIC *) [" ^ nl ^ " " + ^ String.concat "\n " (List.mapi (fun i t -> " (* "^ string_of_int i ^" *) \"" ^ print ~l (t :> nf) ^ "\";") ps) + ^ nl ^ "] [\"*\"];;" ^ nl ;; diff --git a/ocaml/num.ml b/ocaml/num.ml index eb37e4c..4b8cd5e 100644 --- a/ocaml/num.ml +++ b/ocaml/num.ml @@ -2,6 +2,9 @@ open Util open Util.Vars open Pure +(* debug options *) +let debug_display_arities = false;; + (************ Syntax ************************************) (* Normal forms*) @@ -124,7 +127,7 @@ let rec string_of_term l = | #nf as t -> string_of_term_w_pars l t and string_of_term_no_pars_lam l = function | `Lam(_,t) -> let name = string_of_var (List.length l) in - "λ" ^ name ^ ". " ^ (string_of_term_no_pars_lam (name::l) t) + "λ" ^ name ^ ". " ^ (string_of_term_no_pars_lam (name::l) t) | _ as t -> string_of_term_no_pars l t and string_of_term_no_pars l : nf -> string = function | `Lam _ as t -> string_of_term_no_pars_lam l t -- 2.39.2