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
4
votes
2 answers

lisp, CLOS: adding a slot to the lock class

I am trying to add a new slot to the lock class. This is useful because I have a lot of locks in a hierarchy and if I store the parent lock for every lock it becomes easier to detect problems while debugging. Unfortunately, this apparently can't be…
Florian Dietz
  • 877
  • 9
  • 20
4
votes
3 answers

CLOS like object model for PHP

I have returned to php development from Moose and I really miss CLOS like object model for php. Is there some kind of syntaxtic sugar which would allow me to write less code in php when dealing with objects? Just to stress this requirement a bit…
dpavlin
  • 1,372
  • 2
  • 9
  • 18
3
votes
2 answers

How to specialize generic function for subclasses of given class

How can i specialize a generic function to take symbols designating subclasses of given class. For example: (defclass a () ()) (defclass b (a) ()) (defclass c (b) ()) (defclass d () ()) (defgeneric fun (param)) (defmethod fun ((param (
Necto
  • 2,594
  • 1
  • 20
  • 45
3
votes
2 answers

Order of (:before/:after) method invocation in CLOS?

I need some help understanding the order of execution for the following code. I create an instance of pie, using the following: (cook (make-instance 'pie)) I know lisp executes functions from most specific to least specific.. however, it doesn't…
Gregorio Di Stefano
  • 1,173
  • 1
  • 15
  • 23
3
votes
3 answers

In Lisp CLOS, how can a class setter automatically update another slot?

I am new to CLOS. Here is my example: (defclass box () ((length :accessor box-length :initform 0 :initarg :bxl) (breath :accessor box-breadth :initform 0 :initarg :bxb) (height :accessor box-height :initform 0 :initarg :bxh) …
Todd
  • 45
  • 2
3
votes
1 answer

Vectors of CLOS objects in Common Lisp

I'm running into strange behaviour I'm unable to explain in Common Lisp (SBCL 2.3.4). Consider the following test case: (defclass class-a () ((foobar :initarg :foobar :accessor foobar :initform '(foo bar)))) (defclass class-b () …
nathanvy
  • 145
  • 7
3
votes
1 answer

Is it possible to dynamically add one more super class in existing class

In Common-Lisp CLOS Is it possible to dynamically add one more super class in existing class. Update: I wanted to defined defassoc kind of macro that will associated some behaviour with method/function using same argument e.g. (defassoc (gname (s (g…
Sharad
  • 437
  • 1
  • 5
  • 17
3
votes
1 answer

Separating initialization arguments and class slots in Common Lisp Object System for making objects

This asks about initializing slots from other slots. What I want to achieve instead is to take some arguments as input - perhaps but not necessarily to make-instance - and convert these arguments into the class slots for storage. In effect, I want…
digikar
  • 576
  • 5
  • 13
3
votes
2 answers

How to catch parse errors in Lucerne (common lisp)

I'm trying to build a simple rest api in Lucerne, but the clack:call method fails if the json is malformed. So, I extended the bass-app class and added an around method: (defclass tracker-app (base-app) () (:documentation "An extension of…
pricks
  • 341
  • 1
  • 2
  • 12
3
votes
1 answer

SBCL Built executable: "When attempting to set the slot's value to XXX (SETF of SLOT-VALUE), the slot YYY is missing from the object"?

It's completely fine to run #'cl-state-machine-examples/tamagochi:run, But generated executable signals SIMPLE-ERROR like this: Built: https://github.com/ageldama/cl-state-machine/releases/tag/fail-sbcl-slot-value And I get: $…
3
votes
1 answer

How to browse class hierarchy with slime in common-lisp

I'm using emacs,+slime+sbcl. I can go up a class hierarchy while I inspect a class/object through the slime-inspector. But how can I browse subclasses of a specific class ? Is there a slime function (or another way) to do that ?
VinD
  • 119
  • 5
3
votes
3 answers

Object as a parameter of itself in lisp

In Python, I would do like this: class foo: def __init__(self): self.x = self Otherwise, now the object is a parameter of itself. How can I do it in common lisp? (defclass mn () ((pai :accessor mn-pai :initarg :pai …
3
votes
2 answers

What are the generic functions defined by the standard?

In Common Lisp there are a few generic functions defined by the standard, for instance functions to manipulate sequences. However looking at Graham's book ANSI Common Lisp and Steele's book Common Lisp – The language at the relevant chapters, I…
Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57
3
votes
2 answers

How to "cast" an instance to a subclass?

I have an instance of class message I'll call "msg". I have defined a class "my-message" and would like instance "msg" to now be of that class. It sounds to me like it should be relatively straightforward, but I don't know how to do it. change-class…
Arnaud
  • 43
  • 3
3
votes
2 answers

Common Lisp class hierarchy

Greg Pfeil's Class Hierarchy diagram provides a comprehensive picture the Common Lisp type system. But I'm trying to better understand the class relationships at the top of the hierarchy. For a simple example, let (defstruct person name age), and…
davypough
  • 1,847
  • 11
  • 21