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
25
votes
7 answers

CLOS for Clojure?

Does there exist anything like CLOS (Common Lisp Object System) for Clojure?
Eric Grindt
  • 251
  • 3
  • 3
16
votes
3 answers

Lisp: How to override default string representation for CLOS class?

In Common Lisp, how can I override the default string representation of a CLOS class so that calls to format or princ will print something intelligible, even when objects of that class are embedded within other types, such as lists or arrays? For…
sadakatsu
  • 1,255
  • 18
  • 36
14
votes
2 answers

Difference between struct and class in Common Lisp

My understanding of a struct is that it has slots to store data in, has a type, has make-X and slot-accessor functions, and can be specialized on by a method (since it has a type). My understanding of a class is that it has all of the same and…
Reepca
  • 323
  • 2
  • 7
13
votes
1 answer

Advantages of CLOS over other class-based OO systems

I've come across claims that Common Lisp Object System (CLOS) is superior to traditional (class-based) Object-Oriented systems. Wikipedia entry for CLOS mentions differences between the two approaches - mainly multiple dispatch and the separation of…
FilipK
  • 626
  • 1
  • 4
  • 13
12
votes
1 answer

Is there a way to get the slots of a class?

I have a class like this one (defclass shape () ((color :initform :black) (thickness :initform 1) (filledp :initform nil) (window :initform nil))) Is there a function in common-lisp how to get a list of those slots if i only know instance of…
Micky
  • 125
  • 1
  • 7
12
votes
1 answer

How to change class's metaclass

This happens to me time and again: I define the class and forget that I wanted it funcallable or it is, say, Gtk widget class, thus it's metaclass needs to be stated. Once it is defined, however, SBCL doesn't let me change me the metaclass (even if…
mobiuseng
  • 2,326
  • 1
  • 16
  • 30
11
votes
3 answers

How can I unintern a qualified method?

During development I defined an 'initialize-instance :after' method which after a while was not needed anymore and actually gets in my way because inside it calls code that is not valid anymore. Since the unintern function does not have an argument…
Paralife
  • 6,116
  • 8
  • 38
  • 64
11
votes
1 answer

Make clos objects printable in lisp

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.
krzysz00
  • 2,083
  • 12
  • 24
11
votes
2 answers

Test if a class is a subclass of another class in common lisp

How do I see if one CLOS class is a subclass of another CLOS class?
krzysz00
  • 2,083
  • 12
  • 24
10
votes
1 answer

Using Common Lisp CLOS objects as keys in a hashtable?

I'd like to use Common Lisp CLOS objects as keys in a hashtable. I thought it would be as simple as this: (defclass my-class () ((a :accessor a :initarg a))) (defun my-class= (my-instance-1 my-instance-2) (equal (a my-instance-1) (a…
10
votes
3 answers

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

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…
TheEnt
  • 476
  • 1
  • 4
  • 13
9
votes
4 answers

Optional Arguments in defgeneric?

I'm writing some methods to emit HTML for various elements. Each method has the same output, but doesn't necessarily need the same input. The method for echoing a game-board needs to take a player as well (because each player only sees their own…
Inaimathi
  • 13,853
  • 9
  • 49
  • 93
8
votes
2 answers

Remove one method from a generic function

I have added the following method to the generic function speak but would now like to remove this particular method in the REPL without removing the rest of the generic functions' methods. (defmethod speak :around ((c courtier) string) ;…
mwal
  • 2,803
  • 26
  • 34
8
votes
1 answer

common lisp: slot-value for defstruct structures

In common lisp, what can I use to access structure slot using slot name/symbol? What I want is (defstruct point (x 0) (y 0)) (defmacro -> (struct slot) `(slot-value ,struct ,slot)) (setf p (make-point)) (setf (slot-value p 'x) 1) (setf (-> p…
SigTerm
  • 26,089
  • 6
  • 66
  • 115
8
votes
2 answers

When is an initform used?

I'm forming a class for some work on molecular dynamics as follows: (defclass %atom (particle) ((name :initarg :name :initform (error "Every atom in the system must have a name!")) (mass :accessor mass :initarg :mass :initform (getmass name)) …
Shamster
  • 2,092
  • 5
  • 24
  • 27
1
2 3
12 13