Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you evaluate a java.lang.String in clojure

Tags:

clojure

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"
like image 908
aposto Avatar asked Sep 24 '26 03:09

aposto


1 Answers

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.

like image 134
cemerick Avatar answered Sep 26 '26 19:09

cemerick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!