leiningen

reefersleep 2025-06-20T22:03:15.633179Z

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.

reefersleep 2025-06-20T22:04:07.695549Z

It doesn't seem to be documented in lein help run.

2025-06-20T23:24:29.825709Z

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

2025-06-20T23:32:21.447509Z

and of course (prn ...) can be used to print things the same way a repl would

seancorfield 2025-06-21T00:28:34.361769Z

The underlying Java main method returns void, i.e., nothing, so you can't return anything from -main in Clojure -- that's my thinking.

2025-06-21T00:34:25.916229Z

but what would it return to - your exit code is returned to the shell

2025-06-21T00:34:43.139729Z

printing isn't something returning does, it's something a repl does, and your main isn't a repl

seancorfield 2025-06-21T00:37:30.915629Z

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.

2025-06-21T00:38:19.037979Z

oh I see what you were saying

seancorfield 2025-06-21T00:38:34.589349Z

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))

reefersleep 2025-06-21T11:22:10.574889Z

@seancorfield sound reasoning 🙂 Totally forgot that -mainis public static void main 😄 Ages since I touched Java.

reefersleep 2025-06-21T11:22:38.888289Z

Thanks both! I'll be printing 🙂