All Manuals > LispWorks Delivery User Guide > 13 Efficiency considerations when coding for delivery > 13.6 Avoid referencing type names

NextPrevUpTopContentsIndex

13.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 - 13 Dec 2011

NextPrevUpTopContentsIndex