The function delivery-shaker-cleanup
can be used to define a cleanup function that is called after the shaking operation. delivery-shaker-cleanup
stores a pointer to function and a weak pointer to object. After the shaking, the shaker goes through all the object/function pairs, and for each object that is still alive, calls function with object as argument. This is used to perform operations that are dependent on the results of the shaking operation.
If the cleanup function has to be called unconditionally, then object should be t
. The cleanup function should be a symbol or compiled function/closure, unless the evaluator is kept via :keep-eval. The shaker performs another round of shaking after calling the cleanup functions, so unless something points to them, they are removed before the delivered image is saved. This also means that objects (including symbols) that survived the shaking until the cleanup function is called, but become garbage as a result of the cleanup function, are removed as well.
The cleanup function cannot use delivery-value. If the value of one of the keywords to deliver is needed in the cleanup function, it has to be stored somewhere (for example, as a value of a symbol, or closed over). It cannot be bound dynamically around the call to deliver, because the cleanup function is executed outside the dynamic context in which deliver is called.
Suppose the symbol P:X is referred to by objects that are not shaken, but its values are used in function P:Y, which may or may not be shaken. We want to get rid of the value of P:X if the symbol P:Y has been shaken, and set the value of P:X to T if :keep-debug-mode is passed to deliver and is non-nil, or nil
otherwise.
(defun setup-eliminate-x ()
(let ((new-value
(if (delivery-value :keep-debug-mode)
t
nil)))
(delivery-shaker-cleanup
t
#'(lambda ()
(unless (find-symbol "Y" "P")
(let ((sym (find-symbol "X" "P")))
(when sym
(set sym new-value))))))))
(define-action "Delivery actions" "Eliminate X"
'setup-eliminate-X)
This sets up the lambda to be called after the shaking operation. It will set the value of P:X if the symbol P:Y has been shaken.
Notes about the cleanup function:
The cleanup functions are called after the operation of delivery-shaker-weak-pointer is complete, and are useful for cleaning up the operations of delivery-shaker-weak-pointer.
LispWorks Delivery User Guide - 15 Feb 2015