clos

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

蹲街弑〆低调 提交于 2019-12-13 01:12:58
问题 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")

lisp, CLOS: adding a slot to the process class

不问归期 提交于 2019-12-12 20:19:10
问题 My program is getting errors with multithreading, so I want to expand the with-lock-grabbed macro to keep track of the stack of locks a process acquires. I want to do this by simply adding a slot to process to store the lock-stack. Unfortunately, I don't understand how to add a slot at runtime without destroying what's already there. ensure-class completely redefines the class. I don't want this, since I don't know what other slots process already has. How can I add a slot? In particular, I

How do I access an unknown instance's slot using a string?

邮差的信 提交于 2019-12-12 19:32:03
问题 Problem Given an instance, inst and a string attr containing the name of a slot, how can I obtain the value of the slot attr on inst ? Of course, if attr were a symbol rather than a string, I would typically just use (slot-value inst attr) , but it seems I need the package information to properly call intern (see below). Minimal example (defpackage :pack1 (:use :common-lisp) (:export :*inst*)) (in-package :pack1) (defclass temp-class () ((temp-slot :initarg :temp-slot))) (defvar *inst* (make

Replacing an ordinary function with a generic function

杀马特。学长 韩版系。学妹 提交于 2019-12-12 12:13:39
问题 I'd like to use names such as elt, nth and mapcar with a new data structure that I am prototyping, but these names designate ordinary functions and so, I think, would need to be redefined as generic functions. Presumably it's bad form to redefine these names? Is there a way to tell defgeneric not to generate a program error and to go ahead and replace the function binding? Is there a good reason for these not being generic functions or is just historic? What's the considered wisdom and best

How to find the package of a class in lisp?

ε祈祈猫儿з 提交于 2019-12-11 08:14:34
问题 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? 回答1: As Rainer Joswig said, classes aren't defined in packages; symbols have packages and the name of a class is a symbol. If you want to know the value of *PACKAGE* at the time the class definition read, compiled, or loaded

MOP: acess any slot definition ? (mito's col-type)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 01:38:06
问题 I define a class which uses the Mito ORM, the slots define a :col-type : (isbn :accessor isbn :initarg :isbn :col-type (or (:varchar 128) :null)) How to get the :col-type definition ? Since this is a slot in my class definition, is there no generic way to access it, like slot-definition :col-type ... ? On the clos-mop documentation, I only find how to access slot-definition-allocation slot-definition-initargs slot-definition-initform slot-definition-initfunction slot-definition-name slot

How to export slots and accessors from Lisp classes?

痴心易碎 提交于 2019-12-10 17:56:16
问题 This is my class's package: (in-package :cl-user) (defpackage foo (:use :cl) (:export :bar)) (in-package :foo) (defclass bar () (baz)) I can create an instance of bar in package cl-user . CL-USER> (defvar f) F CL-USER> (setf f (make-instance 'foo:bar)) #<FOO:BAR {10044340C3}> But I can't access the member baz . Calling slot-value like so ... CL-USER> (slot-value f 'baz) ... results in this error message: When attempting to read the slot's value (slot-value), the slot BAZ is missing from the

CLOS: how to call a less specific method?

旧街凉风 提交于 2019-12-10 16:13:55
问题 There is a generic method, say incx . There are two versions of incx . One specialized on type a , and one specialized on type b . Type b is a subclass of a . You are given an object of type b , the derived type - but you want to call the method that is specialized on type a . You could do this easily if there wasn't already a method of the same name specialized on type b , but alas, there is such a method. So how do you call the method specialized on type a in such a situation? (defclass a (

CLOS make-instance is really slow and causes heap exhaustion in SBCL

こ雲淡風輕ζ 提交于 2019-12-10 12:57:10
问题 I'm writing an multiarchitecture assembler/disassembler in Common Lisp (SBCL 1.1.5 in 64-bit Debian GNU/Linux), currently the assembler produces correct code for a subset of x86-64. For assembling x86-64 assembly code I use a hash table in which assembly instruction mnemonics (strings) such as "jc-rel8" and "stosb" are keys that return a list of 1 or more encoding functions, like the ones below: (defparameter *emit-function-hash-table-x64* (make-hash-table :test 'equalp)) (setf (gethash "jc

This is a bug in sbcl?

孤街浪徒 提交于 2019-12-10 05:32:15
问题 Why happen this in sbcl? Maybe a bug? (defclass myclass () ((s1 :initform '((a . 1) (b . 2))) (s2 :initform '((a . 1) (b . 2))))) (defparameter ins (make-instance 'myclass)) (setf (cdr (assoc 'a (slot-value ins 's1))) 43) ;; change only slot s1 ;; here my problem (slot-value ins 's1) ;; => ((a . 44) (b . 2))) (slot-value ins 's2) ;; => ((a . 44) (b . 2))) But if change :initform to : (defclass myclass () ((s1 :initform '((a . 1) (b . 2))) (s2 :initform '((a . 1) (b . 3))))) The problem