Different question: lein run -m my-ns seems to not return anything even if my -main fn is run and logically has a return value. I can't figure out whether a return value should be printed or not.
It doesn't seem to be documented in lein help run.
the printing of a return value is done by your repl, your main class usually won't be a repl. if you use System/exit the number you pass will be returned to the shell
and of course (prn ...) can be used to print things the same way a repl would
The underlying Java main method returns void, i.e., nothing, so you can't return anything from -main in Clojure -- that's my thinking.
but what would it return to - your exit code is returned to the shell
printing isn't something returning does, it's something a repl does, and your main isn't a repl
seanc@Sean-win-11-laptop:~/clojure/value$ lein run
Hello, World!
seanc@Sean-win-11-laptop:~/clojure/value$ echo $?
0
seanc@Sean-win-11-laptop:~/clojure/value$
from
(ns return.value
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!")
42)
So, no, returning a value from -main doesn't affect the exit status.oh I see what you were saying
Whereas
seanc@Sean-win-11-laptop:~/clojure/value$ lein run
Hello, World!
seanc@Sean-win-11-laptop:~/clojure/value$ echo $?
42
seanc@Sean-win-11-laptop:~/clojure/value$
from
(ns return.value
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!")
(System/exit 42))@seancorfield sound reasoning 🙂 Totally forgot that -mainis public static void main 😄 Ages since I touched Java.
Thanks both! I'll be printing 🙂