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
6
votes
1 answer

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

CL-USER> (defclass a () ()) CL-USER> (defclass b (a) ()) CL-USER> (make-instance '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
mck
  • 1,334
  • 2
  • 12
  • 20
6
votes
1 answer

Specialising on Vectors and Matrices

I am using common-lisp for my real-time graphics experiments and so far it has being great. My requirements for speed and easy compatibility with cffi mean I am using 'typed' arrays. The one area of the code which really feels ugly is the generic…
Baggers
  • 3,183
  • 20
  • 31
5
votes
1 answer

Common Lisp: How to check if a slot is bound? (CLOS)

Say we have a slot without :initform (defclass foo () ((x :reader x :initarg x))) How can I check if slot x of an instance of foo is bound? There is a way to do this with MOP, which I find very ugly. Is there an easier way? I'd rather resort…
mck
  • 1,334
  • 2
  • 12
  • 20
5
votes
2 answers

Is generic dispatch in Common Lisp Object System the same as Dynamic Dispatch in classic OOP?

I am reading the book Object Oriented Programming in Common Lisp from Sonja Keene. In chapter 2, the author says: The procedure for determining which methods to call and then calling them is called generic dispatch. It happens automatically…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
5
votes
2 answers

Why does calling `make-instance` in `let` work differently?

I'm exploring some possibilities of Common Lisp syntax and I wanted to make an :around method on make-instance to return some arbitrary value in some cases. For sake of simplicity, let it be nil, when I don't pass a needed argument. And it works,…
Bartek Lew
  • 101
  • 5
5
votes
2 answers

Common Lisp Multiple Metaclasses

Having recently discovered an active fork of weblocks, I would like to combine it with the ORM library mito. Weblocks defines a macro defwidget, which in practice wraps defclass like so: (defclass my-class () ((slot)) (:metaclass…
otyn
  • 55
  • 2
  • 5
5
votes
2 answers

This is a bug in sbcl?

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…
5
votes
3 answers

Access CLOS-object slots from used external package

I am learning to structure my CL programm and now having trouble to use the CLOS while programming in the large with packages. package.lisp (defpackage :my-project.a (:use :cl) (:export create-my-object my-object ; EXPORT SINGLE…
LeinadLime
  • 81
  • 6
5
votes
1 answer

Custom slot options don't apply any reduction to its argument

Say if I define a metaclass that enhances standard slots with a validator slot, when I pass :validator (clavier:valid-email "The email is invalid") as an option, instead of storing the result of of the expression, which is a funcallable, it stores…
PuercoPop
  • 6,707
  • 4
  • 30
  • 40
5
votes
1 answer

How to write (simple) macro?

I need to write a macro (with-hooks (monster method who what) &body body) for a game I'm writing. Monster is a CLOS object, method and who are strings and what is a function (#' notation). The macroexpansion would be something to the effect…
krzysz00
  • 2,083
  • 12
  • 24
5
votes
3 answers

Diamond inheritance and the Common Lisp Object System

I am trying to find a solution to typical diamond inheritance problem in Common Lisp CLOS. The code : (defclass C1.0 () ... ) (defclass C2.1 (C1.0) ...) (defclass C2.2 (C1.0) ...) (defclass C3.0 (C2.1 C2.2) ...) (defmethod m1 ((obj C1.0))…
RKS
  • 309
  • 1
  • 6
5
votes
2 answers

defclass type information for performance

In the following program, removing the line (declare (type (simple-array bit) arr)) makes running time increase by more than a factor of 3, using SBCL. The type information given in the defclass macro via :type on the other hand appears to have…
Lasse Kliemann
  • 279
  • 2
  • 8
5
votes
1 answer

additional properties to slot definition

http://mop.lisp.se/concepts.html says: An implementation is free to add additional properties to the canonicalized slot specification provided these are not symbols accessible in the common-lisp-user package, or exported by any package …
user1312837
  • 1,268
  • 1
  • 11
  • 29
5
votes
1 answer

cross-package defgeneric/defmethod in Common Lisp?

What is the right way to define a generic in package A and to provide a method for this generic in package B in CLOS? Thank you in advance! Example: (defpackage :common (:use :cl)) (in-package :common) (defgeneric compare (a b)) (defmethod…
Damg
  • 406
  • 3
  • 9
5
votes
4 answers

Undefining a class and all its methods in Common Lisp

I would like to undefine a class and all of its methods but after a quite thorough search on Googlore I have been unable to find a clue about how to do this. I am using an implementation of Commmon Lisp called CCL (Clozure CL).
Mike2012
  • 7,629
  • 15
  • 84
  • 135
1 2
3
12 13