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

What's the equivalent of constructors in CLOS?

How would you express the following Java code in Lisp? class Foo { private String s; public Foo(String s) { this.s = s; } } class Bar extends Foo { public Bar(int i) { super(Integer.toString(i)); } } In Lisp,…
Tobias Brandt
  • 3,393
  • 18
  • 28
8
votes
3 answers

memory usage by objects in common lisp

Is there a way to find out how much memory is used by an instance of a class or basic data types in general? I have a toy webframework in cl that creates and manages web pages with instances of classes that represent the html tags and their…
Farzad Bekran
  • 489
  • 1
  • 6
  • 13
8
votes
4 answers

Is there a generic method for cloning CLOS objects?

I'm looking for a way to clone CLOS objects in a shallow manner, so the created object would be of the same type with the same values in each slot, but a new instance. The closest thing I found is a standard function copy-structure which does this…
postfuturist
  • 22,211
  • 11
  • 65
  • 85
7
votes
2 answers

How to force slot's type to be checked during make-instance?

Let's say I have the following class declaration: (defclass foo-class () ((bar :initarg :bar :type list))) When I create an instance of this class, make-instance won't check whether passed arguments satisfy types of slots. So, I can…
OlegTheCat
  • 4,443
  • 16
  • 24
7
votes
3 answers

Using CLOS class instances as hash-table keys?

I have the following class: (defclass category () ((cat-channel-name :accessor cat-channel-name :initarg :cat-channel-name :initform "" :type string :documentation "Name of the channel of this category") (cat-min :accessor…
JNevens
  • 11,202
  • 9
  • 46
  • 72
7
votes
5 answers

Does Java support dispatching to specific implementations based on types of multiple objects like Lisp does?

Reading myself into Lisp, currently on this page (http://landoflisp.com), I found the following statement on the second last paragraph on the page that shows when clicking the link CLOS GUILD: The important thing to note about the example is that…
Mathias Bader
  • 3,585
  • 7
  • 39
  • 61
7
votes
2 answers

Use of :method option in defgeneric

I notice, upon reading Keene's book, that defgeneric has a :method option, which seems like it allows you to specify a method in the generic definition itself. Most documentation I've seen has all of the applicable methods defined in separate…
amp108
  • 432
  • 3
  • 14
7
votes
1 answer

CLOS make-instance is really slow and causes heap exhaustion in SBCL

I'm writing an multiarchitecture assembler/disassembler in Common Lisp (SBCL 1.1.5 in 64-bit Debian GNU/Linux), currently the assembler produces correct code for a subset of x86-64. For assembling x86-64 assembly code I use a hash table in which…
nrz
  • 10,435
  • 4
  • 39
  • 71
6
votes
2 answers

lisp: How to create temporary method specialization within a scope

In Common lisp: Redefine an existing function within a scope? the OP asked for something similar. But I want to create a method specializer, not a function. Essentially suppose that a method is defined such: defmethod my-meth ((objA classA) (objB…
Paralife
  • 6,116
  • 8
  • 38
  • 64
6
votes
1 answer

How to use a "taken" word as a CLOS generic

Generics seem to offer a nice facility for pulling out a common word and letting it act on things according to the types you pass it, with extensibility after-the-fact. But what about common words that are already taken and aren't defined as…
6
votes
2 answers

Comparing Common Lisp with Gambit w.r.t their library access and object systems

I'm pretty intrigued by Gambit Scheme, in particular by its wide range of supported platforms, and its ability to put C code right in your Scheme source when needed. That said, it is a Scheme, which has fewer "batteries included" as compared to…
SuperElectric
  • 17,548
  • 10
  • 52
  • 69
6
votes
5 answers

Trying to learn: Object Reorientation, and generic functions in LISP!

im reading Practical common Lisp as a result of another question. I just read chapter 16 and 17 where you can find how LISP manages objects. But after a couple of years of thinking how Java manages objects, i cant really seem to understand how you…
DFectuoso
  • 4,877
  • 13
  • 39
  • 55
6
votes
3 answers

Comprehensive guide on common lisp types

Maybe this question is too general, nevertheless i'll try: Is there any comprehensive guide on types in common lisp? I'm kind of confused about this subject: Why are non-primitive types declared in make-array's :element-type are promoted to t? Is…
leetwinski
  • 17,408
  • 2
  • 18
  • 42
6
votes
3 answers

Initializing slots based on other slot values in Common Lisp Object System class definitions

In my class definition, I want to initialize one slot based on the value of another slot. Here is the sort of thing I would like to do: (defclass my-class () ((slot-1 :accessor my-class-slot-1 :initarg slot-1) (slot-2 :accessor my-class-slot-2…
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202
6
votes
2 answers

Using a Common Lisp user-defined type in defmethod

I'd like to be able to use a defined type as a parameter specializer to a defmethod. The motivation is readability and flexibility to change at a later stage. Somehting like this: (deftype foo () 'fixnum) (defmethod bar ((x foo)) ...) (defmethod…
user3414663
  • 531
  • 3
  • 11
1
2
3
12 13