Suppose we use SBCL's #'save-lisp-and-die to create an server applicatioon App1, which works very well. Now we want to replace a function #'func1 with a new version without stopping App1. How can we do it in Common Lisp ?
Any suggestion is appreciated !
I personally ensure that SWANK (the server part of SLIME) is running, so that I can connect to the image at any time with Emacs+SLIME and redefine whatever I want.
Then in Emacs, you can
M-x slime-connect
, and follow the prompts.If you don’t want to do this for whatever reason, your implementation might offer something specific.
You need to load the new function definition. Then new function will be available immediately; code will call newly loaded function.
New function definition may be loaded in many ways:
(load (compile-file "file.lisp"))
wherefile.lisp
is a source code for function(load "file.fasl")
wherefile.fasl
is compiled source code(eval (defun ...))
Of course, there are exceptions and complications:
(function FOO)
whereFOO
is the name of a function), it will retain its old value. To avoid this, use symbols instead of function pointers (symbols arefuncall
able).fmakunbound
their symbols.But in practice, code reloading works well in most Common Lisp implementations.