And if anyone is curious, I've now got a Clojure program that works
pretty much exactly like this Java program, including using gen-class
to extend java.io.ByteArrayOutputStream with a new method, and access
two protected (non-static) fields of the superclass:
http://shootout.alioth.debian.org/u32/program.php?test=revcomp&lang=java&id=4
The Clojure program is here:
http://github.com/jafingerhut/clojure-benchmarks/blob/master/revcomp/revcomp.clj-13.clj
I don't consider it to be a prime example of easily readable Clojure
code, but it is pretty darn fast compared to the previous fastest
Clojure program I had for this problem. It should be up on the
Shootout web site in a day or two.
Thanks,
Andy
On Jan 28, 2011, at 4:20 PM, Andy Fingerhut wrote:
That was what I was missing. Thanks, Aaron.
Regarding using :gen-class in the ns macro, and also (gen-class) at
the top level, I am using the first because I know it works for AOT
compilation (important for the shootout web site to avoid measuring
compilation as part of the run time). If there is another way to do
AOT compilation without that, I'm all ears if it has important
technical advantages, and/or would be a better example for people
reading these sample programs and learning from them.
I am using the (gen-class) at the top level because I want to extend
another class, and then use that from -main or from a function that -
main calls.
I understand that most people would probably define these classes in
separate files, but for the shootout web site it is advantageous
(perhaps even required -- I'm not sure) that it all fits in one file.
Thanks,
Andy
On Jan 28, 2011, at 4:07 PM, Aaron Cohen wrote:
On Fri, Jan 28, 2011 at 6:13 PM, Andy Fingerhut
<andy.finger...@gmail.com> wrote:
(ns andy.try
(:gen-class))
(gen-class
:name andy.try.ReversibleByteArray
:prefix rba-)
I find it confusing that you have both of ":gen-class in the ns
macro"
(I guess you're using this to get -main) and "(gen-class) at the top
level".
The class you are creating extends no interfaces and defines no
methods. (Note, the only reason that you get a "main" method in one
of
your generated classes is because the :gen-class option to ns
automatically specifies (:main true). If you add (:methods [[reverse
[] void]) to your gen-class statement, it will add a reverse method
to
the generated class which calls your rba-reverse function and returns
void.
I would look into combining the two gen-classes though.
Here's a great blog post that goes into gen-class some more:
http://kotka.de/blog/2010/02/gen-class_how_it_works_and_how_to_use_it.html
--Aaron
--
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
--
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