how to specify that a method argument is a list of (e.g.) string

64 views Asked by At

In CLOS, how to specify that a method argument is a list of (e.g.) strings?

e.g. something like:

(defmethod m1 ((x (every 'string)))  
  (dolist (y x) (print (char y 0)))) 
1

There are 1 answers

5
Numbra On

You can't. Methods can only be specialized on classes, not types. You could manually define the type list-of-strings with deftype and satisfies, but it would still be invalid to use it as a specializer in a defmethod.

From the defmethod entry of the CLHS:

Only required parameters can be specialized. If parameter-specializer-name is a symbol it names a class.