Log in

No account? Create an account

Lisp Usenet classics

Here are some past Erik Naggum Usenet articles for your reading pleasure.



Re: Object Orientation and what it means in Common Lisp

Ok, say that dogs talk by barking, but they only have one thing to say all the time.

The thing a particular instance or class has say could be considered a property of the instance or class, not of the talk operation. So you might have classes that look like:

(defclass dumb-animal ()
  ((on-its-mind :initarg :on-its-mind :reader on-its-mind)))

(defclass enlightened-thinker ()
  ((on-its-mind :initarg :on-its-mind :accessor on-its-mind)))

(defclass dog (dumb-animal)
  ((on-its-mind :allocation :class))
  (:default-initargs :on-its-mind "Woof!"))

(defclass chicken (dumb-animal)
  ((on-its-mind :allocation :class))
 (:default-initargs :on-its-mind "Bock bock bock!"))

(defclass person (enlightened-thinker)

(defun say (stuff)
  (write-line stuff))

(defgeneric speak-your-mind (thing)
  (:method (thing)
    (say (on-its-mind thing))))

(defmethod slot-unbound (class (object enlightened-thinker)
                         (slot-name (eql 'on-its-mind)))
  (error "Nothing on your mind?"))

A person might change what is on his mind, but a dog or chicken won't.

Anyway, you can model everything you want to in CLOS; it helps to understand what's with the grain and what isn't.