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
1
vote
2 answers

Strange class precedence list in sbcl

In sbcl, *(sb-mop:class-precedence-list (find-class 'cons)) ==>(# # # #) Isn't it strange that cons inherits from list and not the other way around? What am I…
Paralife
  • 6,116
  • 8
  • 38
  • 64
1
vote
1 answer

Specializing behavior of describe method, as explained by Sonya E. Keene

In the book Object Oriented Programming in COMMON LISP by S. Keene, she introduces specializing the behavior of the describe generic function by providing an :after method for some classes, but this will result in an error in SBCL and…
Student
  • 708
  • 4
  • 11
1
vote
2 answers

How to convert json-string into "complex" CLOS object using cl-json library?

I'm coming from this question How to convert json-string into CLOS object using cl-json library? in which an answer provides a way to instantiate an object of a told class using an input json. Sadly the answer misses recursivity, as slots of the…
VinD
  • 119
  • 5
1
vote
1 answer

How to point to a defgeneric instance in common-lisp CLOS

lisp beginner here. I get how to point to a specific method instance using function find-method and I see from using slime inspect on the returned method instance that it has a slot %GENERIC-FUNCTION, but I cannot use it. (why does (slot-value…
VinD
  • 119
  • 5
1
vote
3 answers

How to execute a function on setf place

I have a list which contains some symbols and values. The goal is to setf the class slot with the accessor, whose symbol is provided by the list : (defclass my-class () ((attr :accessor attr))) (let ((to-call '(attr "some-value")) (obj…
Fnifni
  • 319
  • 1
  • 10
1
vote
0 answers

Is there any situation where a slot would not be initialized to its initform?

I'm trying to learn about CLOS, and have written an example class. It has 4 slots, named slot1-4. slot2 has an initform, yet none the less I am getting this error: "The slot COMMON-LISP-USER::SLOT2 is unbound in the object". I am failing to see…
Charlim
  • 521
  • 4
  • 12
1
vote
1 answer

Why aren't generic functions the same as accessor functions lisp

From the things I have read I understand that Accessor functions in CLOS allows for the programmer to get and set variables and it generates a generic function of the name that was give in to the accessor to which you need to define different…
jakHunter
  • 305
  • 3
  • 13
1
vote
2 answers

Suppress style-warning on make-instance in sbcl

I have two packages with a class defined in each. The second class inherits from the first but has a slot of the same name. The intention is indeed to override the slot. (defpackage :foo (:use :cl) (:export foo)) (in-package :foo) (defclass…
user3414663
  • 531
  • 3
  • 11
1
vote
1 answer

Weird error when compiling Common Lisp code

I am getting the following error trying to compile some code: Lambda list of method # is incompatible with that of the generic function INITIALIZE-INSTANCE. Method's lambda-list : (PAT::E) Generic-function's : (CCL::INSTANCE &REST…
nosefouratyou
  • 331
  • 1
  • 8
1
vote
2 answers

Common Lisp: CLOS and packages / how to import and merge generics

Suppose we have two packages, each defines a class and exports symbols for slots/generic methods with identical names. (defpackage pkg1 (:export _class1 _slot _reader _method)) (in-package pkg1) (defclass _class1 () ((_slot :initform "SLOT111"…
AlexDarkVoid
  • 485
  • 3
  • 12
1
vote
1 answer

LISP - get all method names from a class

Can I get in LISP all the method names from a class? Actually I need the methods, which have set- in their names.
1
vote
2 answers

How to get all instances of a class in common lisp?

Imagine I have a class: (defclass person () ()) And then I make some instances: (setf anna (make-instance 'person)) (setf lisa (make-instance 'person)) How can I get either the objects themselves or the symbol names they were assigned…
anonymous
  • 1,522
  • 14
  • 24
1
vote
1 answer

How to describe and implement and interface in common lisp

I am implementing a graph data structure that will store arbitrary objects as vertices. I want to define an interface for things like getting the key for an object so that all vertices can have a key. In my mind, this sounds like where I might use…
gaigepr
  • 905
  • 1
  • 10
  • 17
1
vote
2 answers

Problem with access of slots in Lisp (CLOS)

I have a Node class that has an 'element' slot which contains a list with numbers and one letter, for example: '(1 2 3 b 4 5 6) (defclass node () ((element :reader get-element :writer set-element :initform '() …
Xap
  • 77
  • 3
  • 7
1
vote
1 answer

Use superclass constructor?

So I have classes (defclass foo () ((a :initarg :a :accessor a) (b :initarg :b :accessor b))) (defclass bar (foo) ((c :initarg :c))) And a constructor (defun make-foo (a b) (make-instance 'foo :a a :b b)) Is there a simple way to define…
wrongusername
  • 18,564
  • 40
  • 130
  • 214