/not-clos

Tiny Common Lisp object system

Primary LanguageCommon LispGNU General Public License v3.0GPL-3.0

not-clos

not-clos if a small object system implementation for Common Lisp.

Features

Basic features are currently implemented

  • Creating objects
  • Initialization forms for variables not set at object creation
  • Automatic setters and getters
  • Defining methods

Missing features

  • It’s rather slow - I have some ideas for optimization but I’m not sure I’ll bother implementing them
  • There is currently no inheritance/polymorphism

Implenetation restrictions

There were a few self-imposed restrictions when writing this system:

  • No use of arrays - each object is an immutable list
    • For this reason when an object’s value is changed a brand new modified object is created, then the symbol is rebound to that object with a macro.
    • This is obviously not the most efficient way.
  • No use of iteration
    • Mapping to lists is used a lot
    • Where there was no way around it tail-call optimized recursion was used instead.

note :tail call optimization only works on some implementations!

There is no practical reason for these restrictions, don’t look for one ;)

Why should you use not-clos?

Short answer: you probably shouldn’t.

This was more than anything a programming exercise for me, Common Lisp already ships its great object system out of the box.

Examples

(load "not-clos.lisp")

(not-clos:make-object rectangle ((x1 0) (x2 10) (y1 0) (y2 10)))

(defvar my-rect (make-rectangle))

(rectangle-defmethod calc-area ()
		     (* (abs (- self-x1 self-x2)) (abs (- self-y1 self-y2))))

(format t "~a~%" (rectangle-calc-area my-rect))

See ~main.lisp~ for full example.