Next Prev Up Top Contents Index

delivery-shaker-cleanup

Function

Signature: delivery-shaker-cleanup object function

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 this function with the 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, the 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 shaken away 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 shaken away 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.

An example:

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:

  1. It does not call delivery-value itself. Instead, it closes over the value.
  2. It does not contain pointers to P:X or P:Y. In this case, it is specially important not to keep a pointer to P:Y, because otheriwse it is never shaken.
  3. It does not assume that P:X will survive the shaking.

[ The code as it is assumes the the package "P" is not deleted or smashed ]

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 - 11 Dec 2001

Next Prev Up Top Contents Index