clos

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

吃可爱长大的小学妹 提交于 2021-01-27 19:59:46
问题 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

Is there a way to gather slot-definition-readers from all the inheritance tree?

廉价感情. 提交于 2020-01-11 10:23:27
问题 The generic function slot-definition-readers gets an argument that must be a direct-slot-definition . If an object is an instance of a class that inherits from another class how can I get hold of the readers of all the effective-slots of the object? Do I manually have to traverse the tree and call slot-definition-readers on the result of class-direct-slots in each superclass, gathering the results, or is there another way that I am not aware of? 回答1: This "community wiki" answer is here to

Is there a way to gather slot-definition-readers from all the inheritance tree?

只愿长相守 提交于 2020-01-11 10:23:11
问题 The generic function slot-definition-readers gets an argument that must be a direct-slot-definition . If an object is an instance of a class that inherits from another class how can I get hold of the readers of all the effective-slots of the object? Do I manually have to traverse the tree and call slot-definition-readers on the result of class-direct-slots in each superclass, gathering the results, or is there another way that I am not aware of? 回答1: This "community wiki" answer is here to

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

别说谁变了你拦得住时间么 提交于 2019-12-25 04:11:53
问题 This question already has an answer here : Is there a way to get the slots of a class? (1 answer) Closed 3 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. 回答1: How about (mapcar #'slot-definition-name (class-slots class)) 来源: https://stackoverflow.com/questions/40884764/lisp-get

Make clos objects printable in lisp

泪湿孤枕 提交于 2019-12-23 07:15:45
问题 If you want to make CLOS objects in common lisp printable (print readably), how do you go about doing this without using anything but print and read. 回答1: There are two parts to doing this, at least in my solution, however you will need this function (thanks to the guys at cl-prevalence for this ( warn LLGPL ) (defun get-slots (object) ;; thanks to cl-prevalence #+openmcl (mapcar #'ccl:slot-definition-name (#-openmcl-native-threads ccl:class-instance-slots #+openmcl-native-threads ccl:class

Make clos objects printable in lisp

杀马特。学长 韩版系。学妹 提交于 2019-12-23 07:14:12
问题 If you want to make CLOS objects in common lisp printable (print readably), how do you go about doing this without using anything but print and read. 回答1: There are two parts to doing this, at least in my solution, however you will need this function (thanks to the guys at cl-prevalence for this ( warn LLGPL ) (defun get-slots (object) ;; thanks to cl-prevalence #+openmcl (mapcar #'ccl:slot-definition-name (#-openmcl-native-threads ccl:class-instance-slots #+openmcl-native-threads ccl:class

Equivalance of instanceof for CLOS? How to check if instance is inherited from another object?

故事扮演 提交于 2019-12-22 05:14:51
问题 CL-USER> (defclass a () ()) CL-USER> (defclass b (a) ()) CL-USER> (make-instance 'b) #<STANDARD-CLASS B> What predicate function can I call on my instance b, which returns T if it was inherited from a? In the vein of: CL-USER> (instanceof 'a *) T 回答1: Class names are also type names, so: (typep * 'a) See Integrating Types and Classes : http://clhs.lisp.se/Body/04_cg.htm Or you could do this: (defmethod is-an-a-p ((x a)) t) (defmethod is-an-a-p ((x t)) nil) 来源: https://stackoverflow.com

Hierarchy of standard-object and standard-class in Common Lisp

怎甘沉沦 提交于 2019-12-21 04:02:08
问题 I'm studying Common Lisp (with Lispworks) and I'm trying to get into class system right now. There is a class called standard-object and it is defined as The class standard-object is an instance of standard-class and is a superclass of every class that is an instance of standard-class except itself. (taken from http://www.lispworks.com/documentation/HyperSpec/Body/t_std_ob.htm#standard-object) so it is an instance of standard-class On the other hand standard-class is a subclass of standard

memory usage by objects in common lisp

自闭症网瘾萝莉.ら 提交于 2019-12-19 18:57:50
问题 Is there a way to find out how much memory is used by an instance of a class or basic data types in general? I have a toy webframework in cl that creates and manages web pages with instances of classes that represent the html tags and their properties, and as they are supposed to make an html page, they have children in a slot called children. so I was thinking how much a user's session will cost the server if I take this approach. Thanks. 回答1: As far as I know, there is nothing like this for

How to convert json-string into CLOS object using cl-json library?

陌路散爱 提交于 2019-12-13 16:17:20
问题 If there is a class and a json: (defclass foo () ((bar :initarg :bar))) (defvar *input* "\{ \"bar\" : 3 }") How to convert *input* into an instance of foo using cl-json library? I guess it should be something like: (with-decoder-simple-clos-semantics (let ((*prototype-name* 'foo)) (decode-json-from-string *input*))) But it produces: Invalid SB-MOP:SLOT-DEFINITION initialization: the initialization argument :NAME was constant: :BAR. [Condition of type SB-PCL::SLOTD-INITIALIZATION-ERROR] What