When multiple forms are sent to nREPL in a single message, and an earlier form throws an exception, the next ones continue being evaluated. Example:
$ clojure -Sdeps "{:deps {nrepl/nrepl {:mvn/version \"1.8.0\"}}}" -m nrepl.cmdline -i
user=> (/ 1 0) (println "Hello!")
Execution error (ArithmeticException) at user/eval2499 (REPL:1).
Divide by zero
Hello!
This happens because nREPL faithfully mimics Clojure's regular REPL which is streaming-based and doesn't distinguish between two forms coming a single message or in separate ones. nREPL is however message-based and this behaviour in it is artificial. Vice versa, the load-file op (which powers e.g. C-c C-k) disables this behavior.
Does anybody rely on this? Do you ever happen to evaluate multiple forms in a single message and want all of them to be executed regardless of errors?I have noticed this behavior, here's a related example:
user> (+ 1 2))
3Syntax error reading source at (REPL:4:15).
Unmatched delimiter: )
Notice the 3 in there, somewhere. 🙂
I think I understand this behavior, and it makes sense to me, are you considering changing to a different behavior? What would it be, and why would it be better?Your example is about a different thing. Forms are read from the message and evaluated one by one. What I consider changing is when exception is thrown in one form, the rest of the input is discarded without being read and evaluated.
;; now
user=> (/ 1 0))
Execution error (ArithmeticException) at user/eval9623 (REPL:1).
Divide by zero
Syntax error reading source at (REPL:1:9).
Unmatched delimiter: )
;; after change
user=> (/ 1 0))
Execution error (ArithmeticException) at user/eval9623 (REPL:1).
Divide by zero
I'm inclined to make this change because this behavior feels more natural to me in a message-based REPL, and we already do the same for load-file anywayI've run across that behavior occasionally and always found it annoying, so I'd be happy to see it "fixed".
I also think we should probably fix it, and I'm reasonably sure this wouldn't have any negative impact.
I see, thanks for the explanation. I think it would be fine either way. 👍