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:
(def n-cpu (4))
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:
(def n-cpu (.availableProcessors (Runtime/getRuntime)))
Notice how if you replace the method call with an integer, it becomes (def n-cpu 4)
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With