Edit: The two threads of execution I mentioned above are likely what the combination of SLIME + Swank are doing.
Edit: The two threads of execution I mentioned above are likely what the combination of SLIME + Swank are doing.
If the recompiled function is currently running that stack frame and anything deeper won't be affected for that call.
The only thing you can't do is redefine the loop function itself since it never stops running. That's why you factor it so there's no reason to change that function, just the functions it repeatedly calls.
Hope that explanation made sense.
Edit: And yes, the way this is implemented under the hood is that the repl has its own thread. You could do this even in C. In fact people have done this for the Linux kernel for example(at least for binary patches). The great thing in CL is the language is designed with the functionality in mind, and the dev tools just support it, so you get it for free.
The underlying “system message requesting your process to ensure it picks up the code reload” part is quite different, though!
This is why there is no "linking" step in Common Lisp compilation: CL keeps the symbol table around at runtime; C just throws it away.
"All conforming programs must obey the following constraints, which are designed to minimize the observable differences between compiled and interpreted programs:"
[...]
"A call within a file to a named function that is defined in the same file refers to that function, unless that function has been declared notinline. The consequences are unspecified if functions are redefined individually at run time or multiply defined in the same file."