Sigh. Sorry, I'm not an experienced Java developer, and I'm sure there are basic things relating Java packages, directories in classpaths, and Clojure hierarchical namespaces that I just don't have in my head yet. Right now I feel like I'm banging my head against a wall and not getting anywhere by trial and error.

Eventually I want to create a single-file Clojure program, AOT- compiled, that creates a class extending java.io.ByteArrayOutputStream with a new method, similar to this Java program from the shootout web site:

http://shootout.alioth.debian.org/u32/program.php?test=revcomp&lang=java&id=4

(As an aside, the Clojure memory and run time results as compared to Java 6 -server on the shootout web site are looking much better these days than they did a few months ago. For example, here are the comparisons between Clojure and Java -6 server programs when run on a 1-core 32-bit Linux machine:

http://shootout.alioth.debian.org/u32/compare.php?lang=clojure

Careful use of -Xmx command line options helped with the memory use for Clojure and JRuby programs. I'm doing another round of performance tweaks to try to improve the run time of the slowest Clojure programs now, and I'm now working on the reverse-complement benchmark.)


Right now, I am having difficulty even using gen-class to create a class within a file that I want to AOT compile.

Here is the Clojure program that seems like it is somewhere near what I want, which I put into a file named try.clj in a directory containing nothing else except that and a shell script described below:
----------------------------------------------------------------------
(ns try
  (:gen-class))

(gen-class
 :name  try.ReversibleByteArray
 :prefix rba-)

(defn rba-reverse [this]
  (println "In rba-reverse"))

(defn -main [& args]
  (let [N (. Integer valueOf (nth args 0) 10)]
    (println "N=" N)
    (let [buf (new try.ReversibleByteArray)]
      (println "(class buf)=" (class buf))
      (println "(. buf (reverse)) returns " (. buf (reverse))))))
----------------------------------------------------------------------

On Mac OS X with the default Hotspot JVM, I run this shell script:

----------------------------------------------------------------------
#! /bin/bash

java -Dclojure.compile.path=. -classpath $HOME/lein/clj-1.2.0/lib/ clojure-1.2.0.jar:. clojure.lang.Compile try
echo "----------------------------------------"
ls -R
echo "----------------------------------------"
java -server -classpath $HOME/lein/clj-1.2.0/lib/clojure-1.2.0.jar:. try 5
----------------------------------------------------------------------

Here is the output I get:

]% ./do.sh
Compiling try to .
----------------------------------------
do.sh                           try$rba_reverse.class
try                             try.class
try$_main.class                 try.clj
try$loading__4410__auto__.class try__init.class

./try:
ReversibleByteArray.class
----------------------------------------
N= 5
(class buf)= try.ReversibleByteArray
Exception in thread "main" java.lang.IllegalArgumentException: No matching method found: reverse for class try.ReversibleByteArray
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:50)
        at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
        at try$_main.doInvoke(try.clj:16)
        at clojure.lang.RestFn.applyTo(RestFn.java:138)
        at try.main(Unknown Source)


Any tips on getting this simpler program to work, and/or on the goal after that of extending java.io.ByteArrayOutputStream with a new method?

Thanks,
Andy

--
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