Amazing stuff. In particular this finally makes debugging macros sane. For those of you that are using swank-clojure you only need to make minor modifications to swank-clojure to pretty-print your macro expansions to the macro expansion buffer. Even better you can move the cursor to subform macros and expand those inline as well.
For example here is an example from Paul Graham's continuations chapter from On Lisp that I expanded, I did not do this by hand promise ;) (do (clojure.core/defmacro dft2 [tree] (clojure.core/seq (clojure.core/concat (clojure.core/list '=dft2) (clojure.core/list '*cont*) (clojure.core/list tree)))) (clojure.core/defn =dft2 [*cont* tree] (reset! *saved* nil) (clojure.core/let [*cont* (clojure.core/fn [node] (cond (= node 'done) (*cont* nil) :else (do (print node) (restart))))] (=dft-node *cont* tree)))) For you swank-clojure users, all you need to do to get this feature right now is to include the cl-format library in basic.clj (swank-clojure/swank/commands/basic.clj) and change apply-macroexpander to look like the following: (defn- apply-macro-expander [expander string] (let [astr (with-out-str (with-pprint-dispatch *code-dispatch* (pprint (expander (read-from-string string)))))] (subs astr 0 (dec (count astr))))) Of course once cl-format makes into clojure-contrib this should just be the default behavior (or setq-able option) for swank-clojure ;) David On Thu, Mar 12, 2009 at 3:05 AM, Tom Faulhaber <tomfaulha...@gmail.com>wrote: > > I have now "released" the first version of my pretty printer as part > of my cl-format library. It is released under the EPL. > > The pretty printer has two functions that you probably care about: > > (pprint obj) will pretty print the given object, and > (pp) at the REPL will pretty print the last result output, i.e. the > value in *1. > > The pretty printer currently supports two modes: simple and code. > Simple mode prints structure in a standard way that's good for data. > Code mode understands lots of Clojure forms (defn, binding vectors, > condp, etc.) and attempts to print them in an idiomatic way. > > Cl-format is on github at http://github.com/tomfaulhaber/cl-format. > There is a Readme there with instructions, examples, limitations and > futures. I won't even try to put examples here, because google groups > wreaks havoc on formatting. > > The simplest way to get some pretty printing happiness: > 1) Download the jar: > http://github.com/tomfaulhaber/cl-format/raw/master/release/cl-format.jar > 2) Put it in your classpath. > 3) Fire up your REPL > 4) (use 'com.infolace.format) > 5) Use pprint and pp as described above. > > This is definitely a first release and there are sure to be bugs. And > I know there are things missing. So let me know if you're having > problems and I'll try to get things fixed up ASAP. > > Enjoy! > > Tom > > > --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---