Hi, for ages, I've been using the following (somewhat hackish) approach to pretty printing source code that requires special lexical markers to allow statements that continue over more than one line. (e.g. in Fortran
foo = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 and in /bin/sh we have the same with "\\" instead of "&"): open Format;; let continuing = ref true;; let wrap_newline () = let out, flush, newline, space = get_all_formatter_output_functions () in let newline' () = if !continuing then out " &" 0 2; newline () in set_all_formatter_output_functions out flush newline' space;; let nl () = continuing := false; print_newline (); continuing := true;; let _ = wrap_newline ();; (* Nonsensical example: *) for statement = 1 to 3 do printf " @[<2>foo = 1"; for i = 1 to 100 do printf "@, + 1" done; nl () done;; The requirement to end each statement with "nl ()" is tedious in real world applications and the use of the global variable "continuing" violates my sense of aesthetics... Is there a more idiomatic approach that I'm missing? Thanks, -Thorsten -- Thorsten Ohl, Wuerzburg Univ., Physics -- http://physik.uni-wuerzburg.de/ohl _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs