Difference between the 'Standard method combination' and 'Simple method combination' in CLOS

蹲街弑〆低调 提交于 2019-12-13 01:12:58

问题


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")

回答1:


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.



来源:https://stackoverflow.com/questions/16787217/difference-between-the-standard-method-combination-and-simple-method-combinat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!