Can we use Clojure like a general library in Java?

180 views
Skip to first unread message

Qihui Sun

unread,
Jun 1, 2012, 8:53:55 PM6/1/12
to clo...@googlegroups.com
Hi,the Thoughtworks technology radar mentioned below:


Functional programming continues its slow but steady ascent into developer mind share and, increasingly, code bases. New languages like Clojure, Scala, and F# offer great new features. Now libraries such asFunctional Java, TotallyLazy and LambdaJ are back porting some functional language capabilities, particularly around higher-order functions and collections, into Java. We like this trend because it previews common capabilities of future languages yet allows developers to stay in their comfort zone. 

So I am interested,if Clojure can be used like a general library in Java,it will beat above libraries and be awesome !

--
Solomon
Google+: Qihui Sun



Sean Corfield

unread,
Jun 2, 2012, 4:55:33 PM6/2/12
to clo...@googlegroups.com
On Fri, Jun 1, 2012 at 5:53 PM, Qihui Sun <qihu...@gmail.com> wrote:
> So I am interested,if Clojure can be used like a general library in Java,it
> will beat above libraries and be awesome !

Yes, you can instantiate clojure.lang.RT inside your Java code and
load, compile and invoke Clojure code, directly from Java. You can
also write code in Clojure, compile it to .class files, package it as
a JAR and use it like a regular Java library.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

Philip Potter

unread,
Jun 2, 2012, 5:00:19 PM6/2/12
to clo...@googlegroups.com

Yes it can! It's just a jar file after all, so you can use the classes in your java program if you like.

However, clojure data structures typically do not use static typing as java uses it. For example, PersistentVector is a collection of Objects and not genericized. Getting things out of such a vector will no doubt require typecasting, just like the old 1.4 days.

Phil

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Qihui Sun

unread,
Jun 2, 2012, 10:31:23 PM6/2/12
to clo...@googlegroups.com
Thanks above two reply.
As Sean Corfield said,it is a bit complex.If there is a command option,ONE TIME do this,it will more convenient.
For example: 
java -jar clojure-1.5.0.jar -genclasses,will produce clojure-lib-1.5.0.jar,and it is  genericized as Philip Potter mentioned!

Maybe Clojure as a general/regular Java lib will get more widely to adopt,be more successful than a language :).


2012/6/3 Philip Potter <philip....@gmail.com>

Sean Corfield

unread,
Jun 2, 2012, 11:40:11 PM6/2/12
to clo...@googlegroups.com
On Sat, Jun 2, 2012 at 7:31 PM, Qihui Sun <qihu...@gmail.com> wrote:
> For example:
> java -jar clojure-1.5.0.jar -genclasses,will produce
> clojure-lib-1.5.0.jar,and it is  genericized as Philip Potter mentioned!

Sounds like what you want is Leiningen, to generate an uberjar,
optionally with compiled classes.

Karl Krukow

unread,
Jun 3, 2012, 8:43:52 AM6/3/12
to clo...@googlegroups.com
Regarding those... 

Some time ago I created a project containing only the persistent data structures for use with Java et al. 


It is the data structures only so no bootstrap penalty. There are also Java'ish "improvements" like basic Generics and improved performance on the iterator pattern.

It's still on Clojure 1.3 (As far as I recall), but I am planning on taking another iteration.

TODO:

- better Generics support
- more data structures  (tries, RRB-trees)
- include the reducers library support for parallelism

given this is a spare time project, I welcome everyone interested to contribute.

/Karl

Qihui Sun

unread,
Jun 7, 2012, 10:42:29 AM6/7/12
to clo...@googlegroups.com
Thank you! It seems a good begin.

2012/6/3 Karl Krukow <karl....@gmail.com>
Reply all
Reply to author
Forward
0 new messages