Currently a minimal code size solution to print 1 in clojure requires:
(ns Solution (:gen-class))
(defn -main [& args] (print 1))
Clojure code is often not executed via a main function. I should be able to simply write:
(ns Solution)
(print 1)
When I do this, I can see that 1 is printed from the output, but I also get the exception
Exception in thread "main" java.lang.UnsupportedOperationException: Solution/-main not defined
and my code fails, despite completing the challenge. Better yet, if codingame is no longer looking for a specific function to call, I should be able to simply submit:
(print 1)
If I do so now, I can still see that 1
is currently printed to the console. However, my solution fails with:
Exception in thread "main" java.lang.Exception: namespace 'Solution' not found after loading '/Solution', compiling:(NO_SOURCE_PATH:0:0)
Is there any possibility this change could be made? To maintain backwards compatibility, you could instead execute a clojure program from a -main in a separate file you can include with every clojure submission, which will execute the user-provided -main in the Solution namespace only if both exist:
(when-let [main-sym (ns-resolve 'Solution '-main)]
(apply main-sym args))