I’d like to use the Java method: Runtime.getRuntime().availableProcessors() and save the result in a integer variable.
So in Clojure I did this:
(def n-cpu ((.availableProcessors (Runtime/getRuntime)) ))
and this:
(def n-cpu (Integer/parseInt ((.availableProcessors (Runtime/getRuntime)) )))
but none work.
Any suggestions?
If you replace the method call in your version with an integer, this is what you logically have:
Clojure cannot handle the list
(4)because the first item in a non-quoted list must be a function. In this case the first item is an integer, and Clojure doesn’t treat integers as functions. If you remove the unnecessary parentheses, your var definition would look like this:Notice how if you replace the method call with an integer, it becomes
(def n-cpu 4)?