Home > Uncategorized > Awesome Object Oriented System.

Awesome Object Oriented System.

I decided to learn Common Lisp a couple of weeks ago, and I’ve been making my way through Practical Common Lisp. Over the weekend I read the section on the Common Lisp Object System. It blew my mind. First of all, common lisp isn’t a “message passing system”; this makes it different from every other major (imperative) object-oriented programming language I know. That whole, “you define methods as part of the class definition” thing? Yeah, no.
Common lisp defines generic functions (defgeneric), which you then implement with specific methods. The method definition (done in defmethod) specifies the types that the implementation is specific to. It also defines how it should combine with other methods (by default, it is a primary method, but you can have it run before, after, or around the other methods that implement the same function). When you call a generic function on an object, the lisp system takes all of the methods that apply to the type of the object, and sorts them by specificity. Primary methods are sorted in order of increasing generality, and they should deal with the full implementation of a generic function because the expectation is that they will be the primary place for work being done (though they can just call (call-next-method) to pass the buck). before methods are sorted in the same direction, and do not have to call (call-next-method). It can do whatever it wants to the object, and the object will be passed down the chain to whatever other auxiliary methods go before the calling of the primary methods and into the primary methods themselves. And, there are auxiliary methods that are called AFTER the primary methods! These get sorted from most general to most specific. And that’s only the standard method combination! There are others! There’s one that adds the returns from all of the methods, one that shoves them into a list, ones that find max or min, and there are others. If that’s not enough, apparently you can even define your own!
Common Lisp also has, sensibly enough, multiple inheritance. Basically, it deals with specificity of multiple direct superclasses by using the order they appeared in the class definition.
All of this leaves classes to mainly define the slots of objects; there are also some syntactic shortcuts to define default accessors for a slot, and the language provides several ways of setting the values of slots when an object is instantiated. Of course, all I’ve written about so far is a semantic abstraction provided by common lisp. I have to mention that, as a lisp, common lisp provides syntactic abstraction. You can define macros, which are based around the manipulation of lists instead of text because lists are not only the basic data type in lisp, but also the way that code is structured. With this blurring between data and code, lisp code can easily manipulate itself! Awesome!
Anyway, that’s enough about this for tonight. Go learn common lisp! It’s fun!

  1. October 14, 2009 at 6:19 | #1

    I think you’ll like the Meta Object Protocol (MOP). :) Everything is customizable, a great book about it is commonly referred to as ‘AMOP’:

    http://www.amazon.com/Art-Metaobject-Protocol-Gregor-Kiczales/dp/0262610744

    Some of the reference parts of the book is here; http://www.alu.org/mop/index.html

  2. raptros-v76
    October 14, 2009 at 13:42 | #2

    Thanks! I’ll put that onto my reading list; Practical Common Lisp mentioned the MOP but didn’t explain it.

  1. No trackbacks yet.