Re: Adapting a functional pretty-printer to Clojure

2008-11-25 Thread Rich Hickey
On Nov 25, 12:51 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Nov 25, 12:50 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > On Nov 25, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > This approach might just be too inefficient -- perhaps it would be > >

Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]
On Nov 25, 12:50 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Nov 25, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > This approach might just be too inefficient -- perhaps it would be > > best to implement the pretty-printer in an imperative style after all. > > OTOH

Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]
On Nov 25, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > This approach might just be too inefficient -- perhaps it would be > best to implement the pretty-printer in an imperative style after all. OTOH it is pretty darn nifty... user> (pp (clojure.xml/parse "http://catless.ncl.ac

Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]
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

Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread Chouser
On Mon, Nov 24, 2008 at 5:27 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I believe I have fixed all of my stack-space issues except for this > one annoying function (rewritten from the original since the > multimethod wasn't buying me much): > > (defn flatten [x] > (let [type (:type x)]

Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]
I believe I have fixed all of my stack-space issues except for this one annoying function (rewritten from the original since the multimethod wasn't buying me much): (defn flatten [x] (let [type (:type x)] (cond (or (= type :NIL) (= type :TEXT)) x (= type :CONCAT)

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread steve...@acm.org
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

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread [EMAIL PROTECTED]
On Nov 18, 1:20 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Thanks for the advice. I think this works for show-list-children: > > (defn insert-line [x y] >   (doc-concat x (doc-concat (doc-line) y))) > > (defn show-list-children [x] >   (cond (empty? x) >         (doc-nil) >         (=

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread [EMAIL PROTECTED]
On Nov 18, 1:12 pm, Chouser <[EMAIL PROTECTED]> wrote: > On Tue, Nov 18, 2008 at 1:05 PM, [EMAIL PROTECTED] > > <[EMAIL PROTECTED]> wrote: > > > Your implementation needs to get the whole value of pr-str before > > deciding that it is too long to put on a single line. > > That's certainly what i

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread [EMAIL PROTECTED]
On Nov 18, 12:53 pm, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote: > As always: don't copy code blindly! Take a step back and look from a > distance, how you can *translate* the code. For example, in the > show-list-children function, the recursion is just used for iteration. > It starts with x,

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread Chouser
On Tue, Nov 18, 2008 at 1:05 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Your implementation needs to get the whole value of pr-str before > deciding that it is too long to put on a single line. That's certainly what it does, but I don't think it has to. My plan was to use *print-length

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread Meikel Brandmeyer
Hi, Am 18.11.2008 um 17:29 schrieb [EMAIL PROTECTED]: What could be some good strategies to adapt the code I have here to Clojure, where tail calls are not eliminated and structs are not lazy? There is the lazy-map package[1], which also allows lazy (struct)maps. However it is not updated to

Re: Adapting a functional pretty-printer to Clojure

2008-11-18 Thread Chouser
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 a

Adapting a functional pretty-printer to Clojure

2008-11-18 Thread [EMAIL PROTECTED]
Hello everyone, 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: user> (def something '(a b c