85 points · by todsacerdoti · 3y ago · 27 comments
For example, I modified my IPython config to always activate https://ipython.org/ipython-doc/3/config/extensions/autorelo...
It works well for modules with redefined functions. So if you do
from module import f1, f2
ans1 = f1()
ans2 = f2(ans1)
and f2 fails, then you can just modify the code of module and relaunch `ans2 = f2(ans1)`.What is not available is reloading classes, for example if it looks like:
from module import Class
c = Class()
c.f1()
c.f2()
and there is a bug in f2, then the class won't be redefined.I guess there is no perfect way to do it (for example what if f2 needs some variables defined in Class.__init__), but the situation is the same for Lisp with its dynamic typing.
So maybe the situation would be to have some command like `%reload Class`.
The other obstacle is restarting from a frame, and I understand that Python's standard exception handling doesn't allow that. But pdb exists so there should be a solution.
Python is a completely different beast.
CL has the generic function update-instance-for-redefined-class[1] for this, so you can customize what happens to instances when a class gets redefined. I think most developers don't actually define methods for it all that often, but it's there if the defaults don't work for you.
[1]: http://www.lispworks.com/documentation/HyperSpec/Body/f_upda...
Common Lisp and Smalltalk (quintessential dynamic systems) both track the existing instances of a class. If you update the class definition then they can update the existing instances of the class. In CL you'd want to specialize `update-instance-for-redefined-class` to handle the update.
http://clhs.lisp.se/Body/f_upda_1.htm#update-instance-for-re...
- https://github.com/breuleux/jurigged
- https://github.com/reloadware/reloadium
I would imagine lisp can do this on a whole different level. Emacs seems like a testament to that. Basically the entire editor feels like eval()
For the restarting, yeah, I don't know either.
"Howto get out of debug-loop" is very much the same question as "howto quit vim". Takes a while to understand the cryptic "ABORT :R3" is actually the way out.
In SBCL, you can disable the interactive debugger. Put this in your .sbclrc:
(defun print-condition-hook (condition hook)
"Print this error message (condition) and abort the current operation."
(declare (ignore hook))
(princ condition)
(clear-input)
(abort))
(setf *debugger-hook* #'print-condition-hook)
It only prints the error messages. It could be useful when experimenting with a bare-bones REPL on the terminal. For that purpose, see also sbcli and cl-repl on Github.