Hi All -
I am trying to create a quick and dirty to import all java classes in
a directory tree (i.e. - the classes directory)
I am able to create the import statements and was thinking of using
eval to execute the import. However I cannot get this to work.
key line is:
(eval (str "(import '(" p " "(. s replace ".class" "") "))"))
which would evaluate to
I have tried using both the above as well as
(eval (read-string (str "(import '(" p " "(. s replace ".class" "")
"))")))
and basically nothing happens.
The 3 questions are:
1. What am I doing wrong?
2. While researching this, people seem to think that eval should not
be used, and that a macro would be preferable. I am a newbie and have
not gotten the macro thing down :) bout would appreciate some advice
on this , and how it would be accomplished...
3. I am *very* new at this and would appreciate some ideas as to how
this would be more appropriate (i.e. more idiomatic clojure). I tried
using a recur statement rather than the final recursive call, but got
an error : java.lang.UnsupportedOperationException: Can only recur
from tail position (test.clj:52). I am assuming that the doseq
statement is the culprit for this...
(def dir (File. "PATH_TO_CLASSES_FOLDER"))
(defn import-package [f & pkg]
(let [p (cond (empty? pkg) nil
(.startsWith (first pkg) ".") (.substring (first pkg) 1)
:else (first pkg))]
(doseq [x (filter #(or (.isDirectory %) (.contains (.getName %)
".class")) (. f listFiles))]
(let [s (.getName x)]
(if (.isFile x)
(eval (str "(import '(" p " "(. s replace ".class" "") "))"))
(import-package x (str p "." s)))))))
(import-package dir)
Finally - the clojure community is seriously amazing. I have never
seen such helpful and friendly people as on these boards. Hats off to
all...
Thanks
Base
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en