LispWorks Delivery User Guide > 3 Writing Code Suitable for Delivery > 3.2 Efficiency considerations when coding for delivery > 3.2.6 Avoid referencing type names

NextPrevUpTopContentsIndex

3.2.6.1 Referencing types via methods

Code can reference type names either directly as shown in Avoid referencing type names or via type-of in code like this:

(defun foo (x)
  (let ((type (type-of x)))
    (cond ((eq type 'class1) ...)
          ((eq type 'class2) ...)
          ...
          ((eq type 'class1000) ...))))

Instead, you could express the conditional clauses as methods specialized for each class:

(defmethod foo ((x class1)) ...)
(defmethod foo ((x class2)) ...)
...
(defmethod foo ((x class1000)) ...)

This would allow any unused classes to be removed by delivery, because each method is a separate function.


LispWorks Delivery User Guide - 22 Dec 2009

NextPrevUpTopContentsIndex