clojure code to java

1,040 views
Skip to first unread message

Julio Berina

unread,
Apr 30, 2014, 10:05:33 PM4/30/14
to clo...@googlegroups.com
I've been programming a bit in Clojure, and in my opinion it's like making Java programs without typing long Java because of it running on the JVM.  However, I wanna be able to convert my Clojure code to Java code.  I know Leiningen can do that, but I am really clueless at this point, and I don't know what other programs out there will convert Clojure to Java .class file.  Does anyone have any tips?

Andy Fingerhut

unread,
May 1, 2014, 12:56:08 AM5/1/14
to clo...@googlegroups.com
Leiningen can convert Clojure source code to Java .class files (compiled Java byte code, not Java source code), with the help of the Clojure compiler.

I don't know of a way Leiningen can convert that to Java source code, unless there is some feature of Leiningen I haven't learned about yet, or some plugin that does that.

There are several programs out there, some open source, some commercial, that can decompile Java byte code files into Java source code, of varying quality.  I have used a trial version of the AndroChef Java Decompiler 1.0 a few times in the past, and found its results better than one other open source Java decompiler I tried (I don't remember what that was called right now).

    http://www.neshkov.com/ac_decompiler.html

Andy


On Wed, Apr 30, 2014 at 7:05 PM, Julio Berina <julio...@gmail.com> wrote:
I've been programming a bit in Clojure, and in my opinion it's like making Java programs without typing long Java because of it running on the JVM.  However, I wanna be able to convert my Clojure code to Java code.  I know Leiningen can do that, but I am really clueless at this point, and I don't know what other programs out there will convert Clojure to Java .class file.  Does anyone have any tips?

--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Colin Fleming

unread,
May 1, 2014, 1:36:58 AM5/1/14
to clo...@googlegroups.com
You could also check https://github.com/galdolber/clojure-objc, which uses a modified Clojure compiler to output Java source instead of bytecode. It's been subsequently modified to work with ObjC, I'm not sure whether that affects its ability to execute the program as Java or not.

henry w

unread,
May 1, 2014, 4:29:23 AM5/1/14
to clo...@googlegroups.com
for understanding what goes on in clojure to class file compilation, i have found this blog series very interesting: http://blog.guillermowinkler.com/blog/2014/04/27/decompiling-clojure-iii/

Phillip Lord

unread,
May 1, 2014, 5:48:01 AM5/1/14
to clo...@googlegroups.com

I've used procyon

https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler

It decompiles all of clojure.core and produces nicely laid out code (see
below).

package clojure;

import clojure.lang.*;

public final class core$first extends AFunction
{
public Object invoke(Object coll) {
final Object x = coll;
coll = null;
return RT.first(x);
}
}


Phil
--
Phillip Lord, Phone: +44 (0) 191 222 7827
Lecturer in Bioinformatics, Email: philli...@newcastle.ac.uk
School of Computing Science, http://homepages.cs.ncl.ac.uk/phillip.lord
Room 914 Claremont Tower, skype: russet_apples
Newcastle University, twitter: phillord
NE1 7RU

Alex Miller

unread,
May 1, 2014, 8:59:56 AM5/1/14
to clo...@googlegroups.com
In general, the bytecode the Clojure compiler produces is not directly transformable back into Java source by any decompiler I'm aware of.

Phillip Lord

unread,
May 1, 2014, 10:12:14 AM5/1/14
to clo...@googlegroups.com

Really, try procyon.

Of course, it depends on whether you mean "java code that you can look
at, and get an idea of what is going on easier than looking at
bytecode", or "java code that you can compile to get the same thing that
you decompiled". The latter no, but the former works.

Phil

Atamert Ölçgen

unread,
May 1, 2014, 1:27:02 AM5/1/14
to clo...@googlegroups.com
Hi Julio,

There is a difference between `converting Clojure code to Java code` and `compiling Clojure into .class files`. Can you clarify which one are you trying to accomplish?

Also if you can provide some more context we might be able to make better suggestions.
--
Kind Regards,
Atamert Ölçgen

-+-
--+
+++

www.muhuk.com
Reply all
Reply to author
Forward
0 new messages