Re: Pretty-printing and auto-formatting Scheme code
Lassi Kortela 14 Feb 2020 14:01 UTC
> I wrote a Scheme pretty-printer many years ago and it is currently used by many Scheme systems (Guile, Bigloo, slib, …):
>
> https://github.com/skangas/guile/blob/master/module/ice-9/pretty-print.scm
>
> That code could certainly be improved upon, but it already behaves well for general use and it is very portable Scheme code.
Very nice, thanks!
Maybe we should put all the pretty-printers into one Git repo, compare
their features and merge them into a library that can do everything.
I gather from comments around the 'net that figuring out where to put
line breaks is by far the hardest problem in pretty-printing. I think
clang-format (advanced C/C++ auto-formatter) even has some kind of
penalty-points system for figuring it out:
<https://clang.llvm.org/docs/ClangFormatStyleOptions.html>. Are there
some classic papers solving this problem?
(Historical anecdote: Guy Steele and RMS once spent 10 hours hacking on
a pretty printer.
<http://cycle-gap.blogspot.com/2007/09/extreme-pair-programming-guy-steele-and.html>)