tags:

views:

88

answers:

1

How would I eval to the following?

(defn run-clojure-func []
  (println "welcome"))

(defn -main [& args]
  (eval (*func* (first args)))

java exam.Hello "run-clojure-func"
+6  A: 

Two versions for you to consider – entirely equivalent, but useful as points of comparison:

(defn -main [& args]
  ((-> args first symbol resolve)))

and this, using destructuring and no -> macro usage:

(defn -main [[fn-name]]
  ((resolve (symbol fn-name))))

resolve is obviously the key. The docs are your friend. :-) Also, as an unfair generalization, eval is almost never necessary.

Chas Emerick