ANN: Pretty printer is now part of contrib

1 view
Skip to first unread message

Tom Faulhaber

unread,
Apr 6, 2009, 12:24:59 AM4/6/09
to Clojure
By (semi-)popular demand, I have added the pretty printer and the
Common Lisp format function (which are really the same package) into
clojure.contrib. It all lives in the namespace clojure.contrib.pprint.

Important: If you want to use pretty printing, you will have to
compile all the source code in clojure.contrib and not just put it in
in the jar. To do this, need to tell ant where clojure.jar is so that
it can run the compiler. For example, I use:

ant -Dclojure.jar=../clojure/clojure.jar

(This is necessary because pretty printing uses a couple of gen-
classed classes to wrap java Writers.)

I haven't done that much work on the pretty printer since my last
announcement, but there are a few improvements:

- I added support for *print-level* and *print-length* to control how
much output you get.
- Support for a bunch more special forms and let-like structures in
*code-dispatch*
- Support for pretty printing Java arrays
- ~3x basic speedup (or 3x less slow, depending on how you look at
it). On my machine, this translates into about 300 lines of code/
second. More to come here...
- Some fixes to allow for deeper structures (as in "very deep")
without blowing the stack.

All in all, it should be a pretty serviceable pretty printer. More
coming, though...

The documentation is still on github, but I've updated it for
clojure.contrib. Look here: http://github.com/tomfaulhaber/cl-format.

Please let me know if you have issues, suggestions, stuff you'd like
to see first, etc.

Stuart Halloway

unread,
Apr 6, 2009, 8:37:26 AM4/6/09
to clo...@googlegroups.com
Hi Tom,

I think that the ant test tasks should depend on the compilation
tasks, and that users will just have to specify a clojure.jar.

Either that or the default test suite should be smart enough to skip
the pretty printer tests with ant.jar not specified.

Stuart

Tom Faulhaber

unread,
Apr 6, 2009, 3:52:18 PM4/6/09
to Clojure
There are a bunch of things in the build file that "do nothing without
complaining" when clojure.jar isn't set.

I didn't want to make a radical change to the build file with this
checkin but I didn't want users to not get the pretty printer and
wonder why either.

More generally, I think we need to think through how we want contrib
built and tested. I would say that we probably want to force the
compile and fail if clojure.jar isn't specified. And as you say, make
test running dependent on clojure-contrib.jar having been built. (In
general, ant's predilection for ignoring failure has always befuddled
me.)

Another question is whether we should duplicate the classes and
the .clj files in the jar or should we just compile all of them. Is
there some value to having the source there?

I'm happy to tweak these things if we have consensus on how we'd like
to do it.

Tom

Laurent PETIT

unread,
Apr 7, 2009, 1:37:32 AM4/7/09
to clo...@googlegroups.com
Hi,

2009/4/6 Tom Faulhaber <tomfau...@gmail.com>

 
Another question is whether we should duplicate the classes and
the .clj files in the jar or should we just compile all of them. Is
there some value to having the source there?

There certainly some value for both scenario : having classes seems an absolute requirement for some libraries to work, but having .clj files is really interesting for those that want either (show-source) ... in their REPL to work (or in IDEs for jumping to a read-only syntax-colored version of the source file).

But there is also certainly value in having a build with just the classes ? (Though since the whole thing is open source, it's not a problem related to rights, but maybe for some platforms such as Android, some people might want the lightest possible jar ?)

Regards,

--
Laurent

BrianS

unread,
Apr 7, 2009, 8:17:01 AM4/7/09
to Clojure
I use clojure-contrib quite a bit, and I find a lot of value out of
having the clj files in the JAR. First, I find it easier to debug a
project, second there are example CLJ files in the source code on how
to use the libraries, and those are of great interest, and it is much
easier to get to these source files from my IDE if they are in the
JAR. I understand the value a smaller footprint JAR file, so maybe
there can be a property either set in the ant file or allowed as a
parameter of the build file to allow someone to build the lightweight
version of clojure-contrib if needed? Just the point of view of a
user, not a contributor, of clojure-contrib.

Brian

On Apr 7, 1:37 am, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> Hi,
>
> 2009/4/6 Tom Faulhaber <tomfaulha...@gmail.com>

Paul Stadig

unread,
Apr 7, 2009, 11:14:17 AM4/7/09
to clo...@googlegroups.com
Isn't it somewhat standard procedure in the Java world (or at least the Maven world...sorry to bring that up again :)) to distribute with a clojure-contrib.jar and clojure-contrib-sources.jar, one being only the compiled classes and the other only being the source files?


Paul

Laurent PETIT

unread,
Apr 7, 2009, 11:30:51 AM4/7/09
to clo...@googlegroups.com
Indeed, it is, in the world of java source files.

And indeed, even in the IDEs, it is possible to have both jars in the classpath and then gain the same benefits I myself cited above in the thread.

Maybe I was confused because I made a parallel between java classes <> native platform code (via JIT) and clojure source file <> native java classes.

If java classes are not present, clojure behaves as a JIT compiler compiling clojure text source into java classes.
There is no equivalent functionality (as far as I know, at least in a standardized way) for distributing native java code along with (or replacing) java classes.

So I did not relate the debate "should clojure source files be located in the same jar as their generated classes", because it didn't sound equivalent to me to the problem "should java source files be located in the same jar as their generated classes".

Somewhat convoluted, I must confess :-)


It seems to me that clojure core already does what you say : a clojure.jar and a clojure-src.jar. But then again, it's just for java source, not clojure source.

Maybe clojure-contrib could be aligned to what clojure core does ?

--
Laurent

2009/4/7 Paul Stadig <pa...@stadig.name>

Michael Wood

unread,
Apr 7, 2009, 12:08:00 PM4/7/09
to clo...@googlegroups.com
On Tue, Apr 7, 2009 at 5:30 PM, Laurent PETIT <lauren...@gmail.com> wrote:
[...]

> It seems to me that clojure core already does what you say : a clojure.jar
> and a clojure-src.jar. But then again, it's just for java source, not
> clojure source.
>
> Maybe clojure-contrib could be aligned to what clojure core does ?

Clojure has three files:

clojure.jar - All class files (from Java source and Clojure source)
and also the .clj files.
clojure-sources.jar - Java source code.
clojure-slim.jar - Compiled Java class files and Clojure .clj files.

I think what people have been wondering about is another option. i.e.
something like clojure.jar, but without the .clj files (except, of
course, clojure-contrib instead of clojure.)

--
Michael Wood <esio...@gmail.com>

Reply all
Reply to author
Forward
0 new messages