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

CLOS: Format initialization argument list for make-instance

I've been scratching my head on this for a while now - maybe someone could shed some light on how to format an initialization argument list for 'make-instance' from a nested list containing (key value) sublists. Example: (make-instance 'myclass…
marleynoe
  • 121
  • 3
1
vote
1 answer

CLOS: convert symbol to accessor

This is a real beginner question I guess, but I couldn't find the answer here. My problem: I would like to set the value of a slot of a class like so: (setf (accessor class) value) I wrote a small function for this: (defun set-class-slots (class…
marleynoe
  • 121
  • 3
1
vote
0 answers

CLOS: enforce slots have a specific type when initarg, slot-writer?

How can I enforce slot's type in CLOS. I know that (locally (declare (optimize safety))) (defclass foo () ((num :type number... could be answer, but I think it's not portable enough. (only with SBCL, not CLISP 2.49) Or, should I implement those…
1
vote
1 answer

Common lisp CLOS dispatch

Is there a good way to get a generic function to dispatch on the car of a list? I've been working on a symbolic algebra program, and at the moment am storing a lot of data as lists with different keywords as the cars to indicate type. For example,…
Riley
  • 982
  • 1
  • 7
  • 19
1
vote
2 answers

Checking parent class of an object

I would like to know a way how to check if an object is of certain class, or derived from it. E.g.: (defclass a nil nil) (defclass b (a) nil) (defparameter *foo* (make-instance 'b)) (my-function *foo* 'a) ; => t (my-function *foo* 'b) ; =>…
Mark Karpov
  • 7,499
  • 2
  • 27
  • 62
1
vote
3 answers

Change an editable-text value in Allegro CL

I'm trying to change the value of an Editable-Text control in Allegro CL (version 8.0.1) by clicking a Default-Button. I've read about (setf value) but haven't found any examples. The function I have ttached to the on-click event is the following …
foliveira
  • 626
  • 1
  • 8
  • 15
1
vote
1 answer

lisp clos accessor problems

I can't use the clos accessor functions when the class is in a list. Say I have class a: (defclass a () ((a :accessor a :initarg :a))) And I make 2 instances: (defparameter b (make-instance 'a :a 1)) (defparameter c (make-instance 'a :a…
1
vote
1 answer

Lisp Def Method Structure

(defmethod update :before ((a AGENT) (e UPDATE)) (when (null (timestamps a)) (push 0 (pls a)) (push 0 (fitnesses a))) (push (timestamp e) (timestamps a)) (push (price e) (revalprices a)) (preprocess a e) (format T ":BEFORE…
user1234440
  • 22,521
  • 18
  • 61
  • 103
1
vote
3 answers

Calling another overloaded method in Lisp

I couldn't find out if this was possible, and just used a (rather ugly) workaround. Assume we've got a class structure as below: (defclass a () ()) (defclass b (a) ()) and the method: (defmethod print-object ((a1 a) stream) (format stream…
AlbusMPiroglu
  • 645
  • 3
  • 13
1
vote
1 answer

Idiomatic Way Of Creating Class Instances From Config Files

EDIT: I have restructured the question so it is (hopefully) easier to answer. I'm new to CL so it's sometimes hard to describe what I'm trying to do when I'm not even sure what the best way to describe it would be :P I've been learning some Common…
m-renaud
  • 1,275
  • 8
  • 11
1
vote
3 answers

Common Lisp: Controlling macro expansion time

I was working with common lisp, and found myself typing up slot definitions of the following form quite a lot: (name :initarg :name :accessor name) And so I thought to concoct a macro to speed up this. I came up with the following: (defmacro…
1
vote
2 answers

In CLOS method definitions, can a specializer be a list of classes and not a single class?

While it does not make much sense in the general case as it should be done via superclasses, I want to allow "nil" for a particular parameter and avoid having to define a separate method. I'm trying to do something like that (pseudo-code) (defmethod…
Arno
  • 88
  • 6
0
votes
2 answers

Why Common Lisp CLOS matches on a method where the arguments are the wrong class?

I am trying to learn CLOS and bumped into this surprise. I have those 3 action methods that seemingly incorrectly match on my arguments. When I run tryme function, why the action marked with the last argument being ':c' does not trigger the expected…
ruby_object
  • 1,229
  • 1
  • 12
  • 30
0
votes
1 answer

how to specify that a method argument is a list of (e.g.) string

In CLOS, how to specify that a method argument is a list of (e.g.) strings? e.g. something like: (defmethod m1 ((x (every 'string))) (dolist (y x) (print (char y 0))))
Tim Menzies
  • 641
  • 5
  • 14
0
votes
1 answer

How to use `class-direct-superclasses` and `class-precedence-list` in Steel Bank Common Lisp (SBCL)?

In tutorials such as this one, one can simply use: CL-USER> (class-precedence-list (find-class (class-name (class-of 123)))) In LispWorks they're available via your default package-use-list, in Allegro they're exported from ACLMOP. But, how to use…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30