CLOS中“标准方法组合"和“简单方法组合"之间的区别 [英] Difference between the 'Standard method combination' and 'Simple method combination' in CLOS

查看:90
本文介绍了CLOS中“标准方法组合"和“简单方法组合"之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究通用Lisp对象协议(CLOS),但遇到了一个疑问.

有人在CLOS中标准方法组合"和简单方法组合"是什么意思吗?

在简单方法组合"中,具有列表"方法组合是什么意思?

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

解决方案

Common Lisp预定义了标准方法组合.这是默认设置.

另外还有一堆所谓的简单方法组合":+andappendlistmaxminnconcor,和progn.

请记住,方法组合查找哪些方法对于某些参数集适用,然后将它们组合为有效方法,并与参数一起调用. /p>

list方法组合结合了所有适用的主要方法(只有这些),并返回所有结果的列表.

+方法组合结合了所有适用的主要方法(只有这些),并返回所有结果的总和.

以此类推.

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

解决方案

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.

这篇关于CLOS中“标准方法组合"和“简单方法组合"之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆