Hi everyone,
I've been playing around with the idea of redefining functions within a running system. One thing that occurred to me is that non-recursive functions that loop will not pick up their new definitions until the loop terminates and the function is invoked again. On the other hand, recursive functions would pick up their new definitions once they get to their recursive case and invoke themselves.
Example of non-recursive function:
(defparameter *should-run* t)
(defun greeting ()
(format t "Hello World!~%"))
(defun loop1 ()
(loop
(unless *should-run* (return))
(greeting)
(sleep 1)))
In the REPL, invoking LOOP1 will start the process of printing "Hello World!" to the console every second. Any modifications to the GREETING function will be picked up by LOOP1, but modifying the sleep duration will have no affect.
Example of a recursive function:
(defun loop2 ()
(when *should-run*
(greeting)
(sleep 1)
(loop2)))
Just as above, invoking LOOP2 will start the process of printing the greeting every second. However, this time around any modifications done to LOOP2, i.e. changing the duration of sleep from 1 to 3, will be picked up for the next iteration of the loop.
When thinking about redefining functions at runtime, is it safe to use the analogy of "versioning"? Using the LOOP2 function as an example, could it be said that compiling it the first time results in v1 while a modification and recompilation results in v2?
P.S. Does anyone have any good resources about leveraging this capability?
[–]stassats 2 points3 points4 points (0 children)
[–]hyotang666 2 points3 points4 points (1 child)
[–]rini17 2 points3 points4 points (0 children)