opening it up with Common Lisp
Book review: Darwinia
Summer reading: Spin
the Omnivoire's Delimma
the Golem's Eye
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.
Copyright -- Gary Warren King, 2004 - 2006