tags:

views:

139

answers:

2

In trying to optimize C and LISP, looking at the assembler code output by the compiler can be a great help.

Clojure presumably compiles to a JVM bytecode that would be equally helpful.

How do I see it?

+3  A: 

Some hand-made solutions:

haylem
May I ask why the down-vote? As far as I know, these are valid answers on how to examine the bytecode of compiled class files, so they are relevant to Clojure. Maybe there's a more Clojure-y way, but it still works just as well. If something I'm saying is wrong, please tell me what and why.
haylem
I suspect you were down-voted because you said "Google it". It's general knowledge on SO that any well-asked and serious question that hasn't been asked on SO before is an okay question to ask. The idea is for SO to be a part of the google results.
Rayne
Ah. That sounds fair enough, though I didn't mean it as a putting down the OP and implying lazyness on his/her part, just that it provides timeless answers with good results considering it's a fairly common question for JVM languages. My bad, I'll do better next time.
haylem
I was the OP, and I thought yours was a great answer and upvoted it. Thanks. I accepted the other one because it told me exactly what to type!
John Lawrence Aspden
+8  A: 

Clojure dynamically compiles all the Clojure code to bytecode at the runtime. I am not sure how you can see this dynamically compiled bytecode. However, you can do Ahead Of Time (AOT) compilation of your Clojure code yourself and that will generate .class files. Then you can use javap to see the bytecode.

Use the compile function in Clojure/core to compile your namespace:

compile function

Usage: (compile lib)

Compiles the namespace named by the symbol lib into a set of classfiles. The source for the lib must be in a proper classpath-relative directory. The output files will go into the directory specified by compile-path, and that directory too must be in the classpath.

Then use javap:

javap -l -c -s -private MyClass
abhin4v
Sweet! Thank you very much.
John Lawrence Aspden
Note that you have to leave off the .class extension. Confused me for a minute or so.
John Lawrence Aspden