On Nov 18, 12:03 pm, Chouser <[EMAIL PROTECTED]> wrote: > On Tue, Nov 18, 2008 at 11:29 AM, [EMAIL PROTECTED] > > <[EMAIL PROTECTED]> wrote: > > > I looked at Wadler's "A Prettier Printer" paper (http:// > > homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf) and did a > > rote translation of it into Clojure. Then I wrote printing routines > > for sequences and maps -- very barebones. They work OK: > > I started working on a pretty-printer as well. I wouldn't show it to > anybody yet, but I also don't want any unnecessary duplicated effort. > So I'll go ahead and show what I've got so far, and then we can decide > how to proceed. I have no interest in pursuing my solution if it's not > a good approach, or if anyone else would rather pursue it. > > That is, I want to use a pretty printer, not necessarily write one. :-)
I feel the same way, mostly. I'm very new to Clojure and not all that experienced in Lisp or functional programming in general. That's why I started with a port of an existing skeletal implementation. I think the main advantage of Wadler's approach -- not to be confused with my port, which I am sure is in need of fixing-- is that it is bounded -- i.e. the decision to print horizontally or vertically is made after looking ahead W characters (W being the line width). Your implementation needs to get the whole value of pr-str before deciding that it is too long to put on a single line. But then, your implementation actually works and doesn't run out of stack space on short lists. :-) On that topic, my pp function makes no sense -- it should use doseq to take advantage of the laziness. (defn pp ([obj width] (doseq char (pretty width (show obj)) (print char))) ([obj] (pp obj 80))) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---