一边念叨CLOS(在ANSI Common Lisp的由保罗·格雷厄姆),我注意到,有一些可以给九项职能defmethod作为其第二个参数:
+,and,append,list,max,min,nconc,or和progn.根据这个答案,它们被称为简单方法组合.
为什么只有这九个?我不能将任意函数作为第二个参数传递的原因是什么?
假设我定义xor为
(defun xor (&rest args)
(loop for a in args counting (not (null a)) into truths
finally (return (= truths 1))))
Run Code Online (Sandbox Code Playgroud)
(这当然可以改善).我想用以下方法定义描述衣服及其组合的几个类xor:
(defgeneric looks-cool (x)
(:method-combination xor))
(defclass black-trousers () ())
(defclass quilt () ())
(defclass white-shirt () ())
(defclass hawaii-shirt () ())
(defmethod …Run Code Online (Sandbox Code Playgroud) 我是朱莉娅的新手。有没有一种方法可以将列表中的元素相加,使其达到特定的目标值?我已经使用 Python 的 itertools 库完成了此操作,如下例所示,但我发现对于较大的数据集来说它非常慢。
import itertools
numbers = [1, 2, 3, 7, 7, 9, 10]
result = [seq for i in range(len(numbers), 0, -1) for seq in itertools.combinations(numbers, i) if sum(seq) == 10]
print result
Run Code Online (Sandbox Code Playgroud) 在 hunchentoot 源代码中,有一个:after名为initalize-instance 的def 方法。
这个特定的示例是整个项目中调用的少数:after方法之一。initalize-instance
我使用 CLOS 的经验告诉我, 需要一个主要方法:before,:after并且:around可以使用方法。
但在 hunchentoot 包中,我看不到他们如何创建主要方法以使这些:after方法起作用。
我缺少什么?