On Nov 24, 8:17 pm, Chouser <[EMAIL PROTECTED]> wrote:
> One option: You could use a seq instead of all the various structs.

I took your advice and uploaded the rewrite to the files section in
Google Groups, filename is pretty-printer.clj.  It doesn't get a stack
overflow anymore, but it runs out of heap space on my machine trying
to print (pp (range 100000)). (pp (range 75000)) works fine.

This approach might just be too inefficient -- perhaps it would be
best to implement the pretty-printer in an imperative style after all.

One reason I don't like this rewrite is that the doc-nil, doc-concat,
doc-union, doc-line, and doc-text operators are missing. They form an
API for custom pretty-printing layouts. For example, with lazy-cats
the make-show-bracket function looks like this:

(defn make-show-brackets [lbrack rbrack]
  (fn [x]
    (lazy-cat [:CONCAT] [(lazy-cat [:TEXT] [lbrack])]
              [(lazy-cat [:CONCAT] [(lazy-cat [:NEST] [1] [(show-
children x)])]
                         [(lazy-cat [:TEXT] [rbrack])])])))

but with an API from the Wadler paper this would look like:

(defn make-show-brackets [lbrack rbrack]
  (fn [x]
    (doc-concat (doc-text lbrack)
                (doc-concat (doc-nest 1 (show-children x))
                            (doc-text rbrack)))))

or slightly more readably:

(defn make-show-brackets [lbrack rbrack]
  (fn [x]
    (reduce doc-concat (list (doc-text lbrack)
                             (doc-nest 1 (show-children x))
                             (doc-text rbrack)))))

Either way, there's a lot less noise than with the lazy-cat stuff...
the trouble is that the arguments need to be lazy. Macros might help,
though then the "reduce" trick above won't work.

-- Steve
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to