标签: method-combination

CLOS:与任意函数组合的方法

一边念叨CLOS(在ANSI Common Lisp的由保罗·格雷厄姆),我注意到,有一些可以给九项职能defmethod作为其第二个参数: +,and,append,list,max,min,nconc,orprogn.根据这个答案,它们被称为简单方法组合.

为什么只有这九个?我不能将任意函数作为第二个参数传递的原因是什么?

我想要的例子

假设我定义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)

oop language-design common-lisp clos method-combination

2
推荐指数
1
解决办法
133
查看次数

加起来等于一个数字的组合 - Julia lang

我是朱莉娅的新手。有没有一种方法可以将列表中的元素相加,使其达到特定的目标值?我已经使用 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)

arrays julia method-combination

2
推荐指数
1
解决办法
262
查看次数

理解 CLOS:后续方法和主要方法

在 hunchentoot 源代码中,有一个:after名为initalize-instance 的def 方法。

这个特定的示例是整个项目中调用的少数:after方法之一。initalize-instance

我使用 CLOS 的经验告诉我, 需要一个主要方法:before:after并且:around可以使用方法。

但在 hunchentoot 包中,我看不到他们如何创建主要方法以使这些:after方法起作用。

我缺少什么?

sbcl common-lisp clos generic-function method-combination

2
推荐指数
1
解决办法
120
查看次数