天道酬勤,学无止境

clos

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

问题 我一直在研究 Common Lisp Object Protocol (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") 回答1 Common Lisp 预定义了标准方法组合。 这是默认设置。 此外,还有一堆所谓的“简单方法组合”: + 、 and 、 append 、 list 、 max 、 min 、 nconc 、 or和progn 。 请记住,方法组合会查看哪些方法适用于特定的参数集,然后将它们组合成一个有效的方法,并与参数一起调用该方法。 list方法组合结合了所有适用的主要方法(只有这些)并返回所有结果的列表。

2022-05-05 22:10:04    分类:技术分享    methods   lisp   common-lisp   clos   method-combination

Common Lisp class hierarchy

问题 Greg Pfeil 的 Class Hierarchy 图提供了 Common Lisp 类型系统的全面图景。 但我试图更好地理解层次结构顶部的类关系。 举个简单的例子,让(defstruct person name age) ,然后(defparameter *p1* (make-person :name "Yosh" :age 19) 。现在 (typep *p1* 'person) T (typep *p1* 'structure) T (typep *p1* 'structure-object) T (typep *p1* 'atom) T (typep *p1* t) T Hyperspec 说structure-object的优先级列表只有它本身和t 。 atom和structure不是层次结构中的类型吗? t的所有直接子类型是什么? 更一般地说,您如何检索任何给定类型的所有直接子类型或超类型(无需反复试验subtypep )? 或者,有没有办法遍历所有类型的列表? MOP 是否提供获取所有子/超类的功能? 与集合论类比,似乎所有 Common Lisp 类型/类在理论上都可以细分为t的两个子类; 即, standard-object (对应于具有实例的元素,如数字 3、字符串“abc”、结构 s1、方法 m1 等)和standard-class

2022-04-30 12:05:04    分类:技术分享    types   common-lisp   class-hierarchy   clos

How to find the package of a class in lisp?

Suppose I want to find out in which package a class is defined, e.g. say (defclass x ()()) is defined in p1. One way could be to get the package via (symbol-package 'x). the problem with this solution is that x is exported in a different package p2. Any other suggestions?

2022-04-30 08:37:53    分类:问答    lisp   package   common-lisp   clos

LISP: Get all slot names from an class instance [duplicate]

问题 这个问题在这里已经有了答案: 有没有办法获得班级的名额? (1 个回答) 5年前关闭。 我需要用类的属性(它的槽值)制作一个窗口。 这将类似于describe功能。 我的问题是:如何获得该课程的所有插槽名称? 我找不到任何关于它的东西,只有describe功能。 回答1 (mapcar #'slot-definition-name (class-slots class))

2022-04-28 17:33:12    分类:技术分享    common-lisp   clos

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

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

2022-04-28 07:05:53    分类:问答    methods   lisp   common-lisp   clos   method-combination

Using CLOS class instances as hash-table keys?

问题 我有以下课程: (defclass category () ((cat-channel-name :accessor cat-channel-name :initarg :cat-channel-name :initform "" :type string :documentation "Name of the channel of this category") (cat-min :accessor cat-min :initarg :min :initform 0 :type number :documentation "Mininum value of category") (cat-max :accessor cat-max :initarg :max :initform 1 :type number :documentation "Maximum value of category")) (:documentation "A category")) 现在,我想使用这个类作为哈希表的键。 实例的地址可以很容易地与eq进行比较。 然而问题是,这个category类可能有多个相同的实例,我希望哈希表也能将其识别为键。 所以,我试图覆盖make-hash-table函数的:test参数,如下所示: (make-hash-table :test #'(lambda (a b)

2022-04-23 08:29:03    分类:技术分享    common-lisp   hashtable   equality   clos

Redefinition of the print-object method for conses has different effects in different CL implementations

问题 尝试不以标准列表表示法打印 conses,而是始终以点对形式打印,以最小的努力,我以这种方式重新定义了print-object方法: (defmethod print-object((c cons) str) (format str "(~a . ~a)" (car c) (cdr c))) 但是对于不同的实现效果是不同的。 在 Clozure CL 和 LispWorks Personal 中,结果是我所期待的: CL-USER 1 > (defmethod print-object((c cons) str) (format str "(~a . ~a)" (car c) (cdr c))) #<STANDARD-METHOD PRINT-OBJECT NIL (CONS . (T . NIL)) 200A45AB> CL-USER 2 > '(a b c ) (A . (B . (C . NIL))) 而在 SBCL 和 AllegroCLexpress 中,列表的打印方式没有任何变化: * (defmethod print-object((c cons) str) (format str "(~a . ~a)" (car c) (cdr c))) #<STANDARD-METHOD PRINT-OBJECT (CONS T) {10051EBC53}> * '(a b

2022-04-21 19:17:04    分类:技术分享    common-lisp   sbcl   clos   ansi-common-lisp

LISP: Get all slot names from an class instance [duplicate]

This question already has an answer here: Is there a way to get the slots of a class? (1 answer) Closed 5 years ago. I need to make a window with the properties of a class (its slot-values). It would be something like describe function. My question is: How do I get all the slots-name for that class? I wasn't able to find anything about it, only the describe function.

2022-03-24 21:45:15    分类:问答    common-lisp   clos

Redefinition of the print-object method for conses has different effects in different CL implementations

Trying to print conses not in standard list notation, but always as dotted pairs, with the minimum effort, I have redefined the method print-object in this way: (defmethod print-object((c cons) str) (format str "(~a . ~a)" (car c) (cdr c))) but the effect is different for different implementations. In Clozure CL and in LispWorks Personal the result is what I was expecting: CL-USER 1 > (defmethod print-object((c cons) str) (format str "(~a . ~a)" (car c) (cdr c))) #<STANDARD-METHOD PRINT-OBJECT NIL (CONS . (T . NIL)) 200A45AB> CL-USER 2 > '(a b c ) (A . (B . (C . NIL))) while in SBCL and

2022-03-20 07:35:42    分类:问答    common-lisp   sbcl   clos   ansi-common-lisp