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

Can't variables be used within generic function methods? (CLOS/LISP)

I'm learning about generic functions in CLOS. Because of the type of examples I find in textbooks and online, I'm getting very confused. The examples always use the fact that there is multiple dispatch. Based on the argument type, a different…
Kevin Van Ryckegem
  • 1,915
  • 3
  • 28
  • 55
2
votes
1 answer

Specialize Generic Function (Multimethod) on Two Arguments

I am trying to build a binary search tree in common lisp. I have defined the binary search class using the CLOS like this: (defclass bst () ((root :type node :accessor tree-root :initform nil :initarg root))) I am…
2
votes
3 answers

Using dot notation to access CLOS slots

When accessing class slots, instead of writing (defmethod get-name ((somebody person) (slot-value somebody 'name)) is it possible to use the dot notation aka C++, namely (defmethod get-name ((somebody person) somebody.name) ? Otherwise, when there…
Andrei
  • 2,585
  • 1
  • 14
  • 17
2
votes
2 answers

Getters and setters to classes in Common Lisp

I often have a class that is composed of a list of another class. For example, I'll have a vector-list class made up of vectors. To avoid writing long statements, I write a method to access the embedded class. However, this method only acts as a…
audrow
  • 143
  • 1
  • 9
2
votes
2 answers

Override :INITFORM of the class slot in subclass

I need to slightly generalize the default slot value in the subclass. Example: (defclass class-a () ((slot-1 :initarg :slot-1 :initform #'identity) <...> other-slots<...>)) Its subclass is (defclass class-b (class-a) ((slot-2 :initarg…
mobiuseng
  • 2,326
  • 1
  • 16
  • 30
2
votes
2 answers

Common Lisp: how to override slot accessors?

I'd like to control the way the values are saved in slots and what is returned when I read a slot. Here is my class definition: (defclass object () ((name :accessor name-access :initform 'noname :initarg :name) (value…
andrei-n
  • 87
  • 2
  • 5
2
votes
3 answers

How to call a method object with standard functions

How does one call a method object as a function? Closer-mop and clos packages both provide method-function for turning a method object into a function. However, is there a way to do it without including another package? And if not, which package?…
user3446498
2
votes
2 answers

Changing method dispatch in Common Lisp

I'm trying to simulate something akin to Haskell's typeclasses with Common Lisp's CLOS. That is, I'd like to be able to dispatch a method on an object's "typeclasses" instead of its superclasses. I have a metaclass defined for classes which have…
Charles Langlois
  • 4,198
  • 4
  • 16
  • 25
2
votes
2 answers

Redefinition of the print-object method for conses has different effects in different CL implementations

Trying to print conses not in standard list notation, but always as dotted pairs, with the minimum effort, I have redefined the method print-object in this way: (defmethod print-object((c cons) str) (format str "(~a . ~a)" (car c) (cdr c))) but…
Renzo
  • 26,848
  • 5
  • 49
  • 61
2
votes
3 answers

Common Lisp Object System method execution order

I have the following two classes: (defclass person () ()) (defmethod speak ((s person) string) (format t "-A" string)) (defmethod speak :before ((s person) string) (print "Hello! ")) (defmethod speak :after ((s person) string) (print…
Dimitri
  • 1,906
  • 3
  • 25
  • 49
2
votes
2 answers

Does this CLOS code result in a runtime or a compile time error in Common Lisp?

Let's say I write the following piece of code (please forgive any errors, I'm a Lisp newbie and I can't run CL on this machine) (defclass o () ()) (defclass a (o) ()) (defclass b (o) ()) (defgeneric m (x)) (defmethod m ((x o)) (print…
Alexey
  • 1,354
  • 13
  • 30
2
votes
1 answer

Loading a file that specifies an error form, but getting the error

I'm trying to write a small game in (SBCL) Common Lisp, using Quickload and ASDF to define and manage dependencies. It uses CLOS, so I have a directory in project called classes, and in there, a file, locatable.cl. The defclass form for the…
amp108
  • 432
  • 3
  • 14
2
votes
2 answers

Create a polynomial object from a number using change-class

I have written a polynomial class along the lines described in SICP 2.5.3 (except using defclass). I would like to be able to seamlessly add and multiply polynomials and regular numbers but I can't make change-class accept a number. I tried to…
charlieb
  • 587
  • 5
  • 11
2
votes
1 answer

List : list all CLOS classes in a package

I'm sure it's possible to list all classes defined in a package, but I don't know how to do it. Does anybody have the answer ? Thanks,
user984846
  • 263
  • 2
  • 8
2
votes
3 answers

Is there a way to access slots in the superclass list in CLOS?

Is there a way to access slots of superclasses in CLOS? E.g., in Objective C I can perform - (void) frob { [super frob] } This sends a message to the (sole) superclass of frob. Perusing the CLOS documentation suggests that DEFCLASS merges all…
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212