Pergunta

I've been studying the Common Lisp Object Protocol (CLOS) and I came across one doubt.

Does anybody what is the meaning of the 'Standard method combination' and 'Simple method combination' in CLOS?

And in the 'Simple method combination' what does it mean to have a 'list' method combination?

(defgeneric what-are-you? (obj)
   (:method-combination list :most-specific-last))

(defmethod what-are-you? list ((obj fixnum))
   "I am a FIXNUM")

(defmethod what-are-you? list ((obj float))
   "I am a FLOAT")

(defmethod what-are-you? list ((obj number))
   "I am a NUMBER")
Foi útil?

Solução

Common Lisp comes predefined with the standard method combination. That's the default.

Additionally there are a bunch of so-called 'simple method combinations': +, and, append, list, max, min, nconc, or, and progn.

Remember, a method combination looks which methods are applicable for a certain set of arguments and then combines them into an effective method, which it calls with the arguments.

The list method combination combines all applicable primary methods (there are only these) and returns a list of all the results.

The + method combination combines all applicable primary methods (there are only these) and returns the sum of all the results.

And so on.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top