If I understand correctly, pressing Ctrl-C now would exit the REPL
completely and cause you to lose all the state you have accumulated in
the REPL?
So, I guess the question is which is more detrimental to general
developer productivity:
A) losing accumulated state of a potentially long REPL session just
because you wanted to interrupt an infinite loop (or a long computation)
you created by mistake , or
B) not being able to use ThreadLocals across REPL commands
This is not a loaded question btw, I am not trying to be
confrontational. I honestly don't know the answer to this question. I am
leaning towards A, but then again I don't know how many libraries are
using ThreadLocals internally that one would like to use in the REPL.
On the other hand, there might be different ways to solve the problem.
For example, you could keep creating new threads on every REPL command,
but before every new REPL command you just copy the entries in the
Thread.threadLocals map from the old thread to the new thread (you would
need to also copy Thread.inheritableThreadLocals for completeness).
If you don't detest too much the use reflection to poke around private
JDK fields, this could work nicely.
Another solution could be to do what you do now (only one thread for the
whole REPL that dies on Ctrl-C), but then enhance the :replay command to
be able to replay all commands from the previous REPL session. That way
you can at least regain the REPL state you had before you hit that
unfortunate infinite loop.
Of course, when I say "you" above it is meant rhetorically, I am not
suggesting that you (Paul) should personally implement any of this. I'm
just throwing out a couple of ideas to discuss their feasibility.