Questions tagged [clos]

Common Lisp Object System

The Common Lisp Object System (CLOS) is the facility for object-oriented programming which is part of ANSI Common Lisp. CLOS is a powerful dynamic object system which differs radically from the OOP facilities found in more static languages such as C++ or Java.

Source: Wikipedia (Common Lisp Object System)

187 questions
5
votes
2 answers

How to reduce code duplication using method combination but keeping possible early return

I got a set of classes which represent a message that has to be handled. But there is only a limited amount of open spots for handlers. Therefore any "dispatch" of a handler handling an message object has to check first whether there is a free spot.…
Sim
  • 4,199
  • 4
  • 39
  • 77
5
votes
1 answer

Class finalization: how to avoid creating dummy instances?

I've run into a problem that a third-party library needs to act on a class as if it was finalized. After some reading I understand the motivation behind this mechanism, but I don't really know how it functions. Example: (make-instance 'expression…
user797257
5
votes
2 answers

CLOS: How to make a slot have an enforced type of vector of symbols?

I'm trying to create a class that can store a vector of symbols in a slot in SBCL. I cannot figure out how to set it up. My best guess thus far has been (defclass Individual () ((discrete-decisions :type (vector symbol)))) This returns the…
sadakatsu
  • 1,255
  • 18
  • 36
5
votes
1 answer

How to export slots and accessors from Lisp classes?

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…
Jan Deinhard
  • 19,645
  • 24
  • 81
  • 137
4
votes
2 answers

specifying a slot value as a key when removing duplicates

The following code does what I want: 1 (defclass some-class () 2 ((some-slot 3 :initarg :somearg 4 :initform (error ":somearg not specified")))) 5 (defparameter *alpha* (make-instance 'some-class :somearg 3)) 6 (defparameter…
Bill Evans at Mariposa
  • 3,590
  • 1
  • 18
  • 22
4
votes
2 answers

How to make the instances of a class using a metaclass inherit from a specific superclass

I'm trying to implement json serialization API for common lisp. To achieve this I've defined a metaclass called json-class. This metaclass defines the slot options :ignore which are used to ignore specific slots of the object. Since I'm using yason…
MPaga
  • 319
  • 2
  • 6
4
votes
1 answer

Common Lisp: extract methods from generic function

Is there a way to extract a list of methods from a generic function in Common Lisp? For example: (defmethod say ((self string)) ; method-0 (format t "Got string: ~a~%" self)) (defmethod say ((self integer)) ; method-1 (format t "Got integer:…
AlexDarkVoid
  • 485
  • 3
  • 12
4
votes
2 answers

How to portably create a class at run-time in Common-Lisp CLOS

I need to create a class at run-time, possibly without resorting to eval. Knowing that the metaclass protocol is not fully standardized in Common-Lisp, after browsing through the The Common Lisp Object System MetaObject Protocol, I tried the…
Renzo
  • 26,848
  • 5
  • 49
  • 61
4
votes
1 answer

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

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?…
Paralife
  • 6,116
  • 8
  • 38
  • 64
4
votes
1 answer

comparing CLOS objects

I am wondering why there is no built-in equality operator in Common Lisp for comparing CLOS objects (standard-classes). For instance, "equalp" can be applied on arrays, structures, hash-tables, however not on objects. I assume a new test which…
marleynoe
  • 121
  • 3
4
votes
2 answers

Replacing an ordinary function with a generic function

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…
4
votes
1 answer

how to define and call class methods in common lisp / CLOS

I'd like to define methods on class objects, that inherit based upon the class' ancestry in the same way that instances' methods inherit. Is there some way to do this? Here's what's not working: eql-method specialization. Consider this…
Dave Morse
  • 717
  • 9
  • 16
4
votes
2 answers

How can I pass a super-class object to a sub-class constructor?

Let's say I have class A with a couple of slots: (defclass a () ((a-1 :initarg :a-1) (a-2 :initarg :a-2))) And class B that inherits from A: (defclass b (a) ((b-1 :initarg :b-1))) If I want to instantiate B, make-instance will offer me…
mobiuseng
  • 2,326
  • 1
  • 16
  • 30
4
votes
1 answer

Using loop on a macro to generate classes slots in Common Lisp

While making classes on CLOS I've met the same pattern multiple times: (defclass class-name () ((field-1 :initarg field-1 :initform some-value :accessor field-1) (field-2 :initarg field-2 :initform another-value …
fsanches
  • 417
  • 4
  • 9
4
votes
2 answers

List object methods in Common Lisp (CLOS)

Is there any way to get all methods defined for object and check if object responds to specified method? Looking for something like Ruby's "foo".methods (list-methods *myobj*) ;; -> (method0 method1 methodN) And also something like ruby's…
sheikh_anton
  • 3,422
  • 2
  • 15
  • 23