opening it up with Common Lisp

Favorite weblogs

Lisp Related

Bill Clementson

Finding Lisp


Planet Lisp



Talking Points Memo

This Modern World

Working for Change

Other home


Recent Readings

Book review: Darwinia
Reviewed: Friday, August 11, 2006

Summer reading: Spin
Reviewed: Saturday, August 5, 2006

Reviewed: Tuesday, July 18, 2006

the Omnivoire's Delimma
Reviewed: Wednesday, July 12, 2006

the Golem's Eye
Reviewed: Wednesday, May 31, 2006


Closer to MOP / Moptilities conundrum
Tuesday, December 13, 2005

I've started to rewrite moptilities with Closer to MOP as a firmer foundation and I've run into a conundrum. Here is the definition of class-precedence (that's not a great name but please ignore that for now <smile>). It is equivalent to the MOP function class-precedence-list but for convenience's sake you can pass it an object or a symbol naming a class.

(defgeneric class-precedence (class) 
  (:method ((class standard-class))
           (finalize-class-if-necessary class)
           (class-precedence-list class))
  (:method ((class symbol))
           (class-precedence (find-class class)))
  (:method ((class standard-object))
           (class-precedence (class-of class))))

Note that the moptilities package now uses closer-common-lisp rather than common-lisp and all of the various MOP packages from difference implementations. This means that the standard-class symbol in the above definition is c2mop:standard-class. If I call #'class-precedence with a symbol, it calls find-class which returns an instance of <lisp>:standard-class (not c2mop:standard-class). The recursive call then matches on the standard-object method -- not, as you'd naively expect, the standard-class method -- and we end up in an endless recursive loop.

Here's my first thought at fixing things:

(defgeneric class-precedence (class) 
  (:method ((class standard-class))
           (%class-precedence class))
  (:method ((class symbol))
           (%class-precedence (find-class class)))
  (:method ((class standard-object))
           (%class-precedence (class-of class))))

(defun %class-precedence (class)
  (finalize-class-if-necessary class) 
  (class-precedence-list class))

this prevents the recursion but now calling with a symbol causes a recursive call with a standard-class (which still ends up running the standard-object code) and this calls %class-precedence with the (class-of class) which is a standard-class and that isn't what I wanted.

Maybe there some easy way around this that doesn't involve a bunch of #+'ing but I'm not seeing it. Any hints the cosmic unconscious wants to send my way are welcome.


Home | About | Quotes | Recent | Archives

Copyright -- Gary Warren King, 2004 - 2006