In CLOS method definitions, can a specializer be a list of classes and not a single class?

StackOverflow https://stackoverflow.com/questions/10008212

  •  29-05-2021
  •  | 
  •  

Вопрос

While it does not make much sense in the general case as it should be done via superclasses, I want to allow "nil" for a particular parameter and avoid having to define a separate method.

I'm trying to do something like that (pseudo-code)

(defmethod my-method ((obj1 my-class1) (obj2 (or my-class2 null)))
   method-body       )
Это было полезно?

Решение

This is not supported in plain CLOS.

Supported are:

  • no class -> T
  • EQL
  • one class

Другие советы

You could create a mixin class with no slots and add that to the superclass list of all the classes of interest; this makes sense because what you're doing implies that all the classes in your list conform to some type.

Alternatively don't specialize - write a method that is applicable to a superset of the types of interest but only acts on your subset. This may be easier to do but is less clean.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top