> But is the way Clojure works so opaque we need to see byte codes?
> I was hoping someone on the list would have some intuition about
> how the expressions get implemented. In fact I hope it's pretty
> close to what I would naively guess from just reading the code
> as is.

One of the advantages of lisp is that there is a very clear connection
between the code and the mental model of how the code is implemented.

With a little experience it is easy to infer what machine language code
will be generated. Once that becomes second nature it is easy to see
what optimizations can be made (e.g. when to use declare). This becomes
useful in numeric examples where you can get vastly improved code by
adding declarations. If you look at the generated machine code you can
compare it directly to, say, a fortran implementation of the same code.

This is also true of Java code if you look at the generated byte code.
I'm sure that Rich has a very strong sense of what the machine is doing
underneath his code, otherwise why would there be a 32-trie optimization?
How could he know if the transactions were correct? How would he find
where the real optimizations matter?

I know that Java will perform certain run-time optimizations but I
consider these "part of the hardware of the JVM". The real CPU does
similar optimizations, out-of-order execution, integer pipelining,
cache-fetching, branch optimization, micro-op reordering, register
renaming, etc. You can't depend on them from machine to machine.
However, given the same javac compiler you can depend on the generated
code being the same. For some optimizations see
www.hpjava.org/pcrc/doc/rochester/rochester.pdf

The way to develop intuition about Clojure is to see what the JVM will do.
If you program for a living there should be no magic. I would guess, not
having seen your code, that the most likely problem is that your numbers
are boxed and you're spending time unboxing/reboxing. See
http://www.bestinclass.dk/index.clj/2010/03/functional-fluid-dynamics-in-clojure.html
He shows a couple macros for aget! and aset! which might help. There was
also a long thread about boxing based on Rich's fast numerics branch.

I expect others will disagree about the magic, of course, and I'm not trying to
start a flame-war. Some programmers I have worked with did not know what
"byte codes" were and they were still able to generate code (curiously
they tended to be "design pattern programmers" so there may be a connection).

See http://dj-java-decompiler.software.informer.com/3.9 for a piece
of software that can show the byte codes. There are many others.

Tim Daly

--
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

Reply via email to