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

Treat nil as wildcard type

I'm writing a Lisp program and am trying to be a bit conscientious about types. I guess there's performance improvements, but I'm more interested in using type annotations for documentation and safety. The problem is nil. I've run into two problems…
tsm
  • 3,598
  • 2
  • 21
  • 35
2
votes
1 answer

CLOS: What I am doing here, setting a slot in the metaclass?

(ql:quickload :postmodern) (defpackage :test-case (:use :cl) (:import :pomo)) (in-package :test-case) ;; (defclass dao-class (standard-class) ;; ((direct-keys :initarg :keys :initform nil :reader direct-keys) ;; (effective-keys :reader…
PuercoPop
  • 6,707
  • 4
  • 30
  • 40
2
votes
2 answers

lisp, CLOS: adding a slot to the process class

My program is getting errors with multithreading, so I want to expand the with-lock-grabbed macro to keep track of the stack of locks a process acquires. I want to do this by simply adding a slot to process to store the lock-stack. Unfortunately, I…
Florian Dietz
  • 877
  • 9
  • 20
2
votes
1 answer

Difference between the 'Standard method combination' and 'Simple method combination' in CLOS

I've been studying the Common Lisp Object Protocol (CLOS) and I came across one doubt. Does anybody what is the meaning of the 'Standard method combination' and 'Simple method combination' in CLOS? And in the 'Simple method combination' what does it…
Paulo Tomé
  • 1,910
  • 3
  • 18
  • 27
2
votes
2 answers

lisp file pointers in classes

I'm running up against a problem in understanding the CLOS way of handling file access within a class. In c++ I would be able to do this: class Foo { Foo (string filename); // opens the file (my_file) requested by the filename ~Foo (); //…
Shamster
  • 2,092
  • 5
  • 24
  • 27
1
vote
1 answer

clisp, CLOS: retyping an object, later

Suppose I have a class animal, with subclasses horse, duck, and rabbit. Suppose I use make-instance to make several objects of class animal. Much later, I discover, for each of these objects, that it's actually a horse, or a duck, or a rabbit. Is…
Bill Evans at Mariposa
  • 3,590
  • 1
  • 18
  • 22
1
vote
1 answer

How to find the package of a class in lisp?

Suppose I want to find out in which package a class is defined, e.g. say (defclass x ()()) is defined in p1. One way could be to get the package via (symbol-package 'x). the problem with this solution is that x is exported in a different package p2.…
1
vote
1 answer

Improving CLOS memory-efficiency in Common Lisp?

CONTEXT: I've started a long-term project in CL, and one of the subcomponents is a framework for lazy programming, which is meant to be as compatible as possible with external CL code. One of the classes is lazy-cons. (defclass lazy-cons (thunk…
swapneils
  • 149
  • 10
1
vote
2 answers

What is a didatic example of the with-slots macro in CLOS?

The Common Lisp HyperSpec covers the with-slots macro. However, the example is hard to grasp. Is there an easier and more didactic example about it?
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
1
vote
3 answers

Is there a technical reason for the use and absence of `:` in Common Lisp's slot specifiers? Or is it just a pure convention?

I am reading the book Object-Oriented Programming in Common Lisp by Sonja Keene. In Chapter 9, the author presents the following example: (defclass window () ((x :initarg :x-position :accessor x-position) (y :initarg :y-position :accessor…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
1
vote
2 answers

How to use call-next-method in initialize-instance with multiple key arguments CLOS

If I have two classes, a class parent and a class child. (defclass parent () ...) (defclass child (parent) ...) And I've defined 2 different methods for initialize-instance, but the child one takes another argument, and calls…
userEwen
  • 13
  • 3
1
vote
1 answer

Calling Class allocated slot on class-names in Common Lisp

Is there any way to call a :class allocated slot on the name of a class instead of an instance? Something like: (class-alloc-slot 'name-of-the-class)
Student
  • 708
  • 4
  • 11
1
vote
1 answer

Common Lisp method specialized on symbol - can't use in other packages, can't export?

I've been working through Practical Common Lisp's binary parser project, and attempted to split the generics (class and macro definitions) and specifics (specific types and method implementations) into different packages. As such, I have the…
Vivian
  • 1,539
  • 14
  • 38
1
vote
2 answers

Typed lambda functions in Common Lisp

I don't know of any practical uses for this, it just came to my mind whether there is any thing comparable to defmethod to defun for lambda? Something like this (defmacro tlambda (args &body body) (let* ((gf-name (subseq (write-to-string (gensym))…
Student
  • 708
  • 4
  • 11
1
vote
1 answer

What' the meaning of method-generic-function?

I'm learning common-lisp and CLOS. I started with the tutorial from http://cl-cookbook.sourceforge.net/clos-tutorial/ In Section 4.3, it mentioned that A generic function is a lisp function which is associated with a set of methods and dispatches…
chansey
  • 1,266
  • 9
  • 20