[flexi-streams-devel] Programmatic classes scrap boilerplate code
Michael Weber
michaelw+flexi at foldr.org
Sat Apr 21 10:20:50 UTC 2007
Hi Edi,
I looked at flexi-streams' stream.lisp some time ago, and there seems
to be a lot of boilerplate code to combine various mixins to specific
stream classes. Then, there seems to be code for parsing and
combining what basically amounts to mixin designators, which are then
again mapped on the specific stream classes.
The underlying issue is not new. AMOP describes a nice way around it
which creates classes composed from several mixins programmatically.
About a year or so ago, Christophe Rhodes fixed SBCL so that it
accepts generalized class names. The support code is little, you can
find it here (usage example at the end of this mail):
http://www.foldr.org/~michaelw/lisp/amop-programmatic-class.lisp
I can't tell how well this is supported in Lispworks and other
implementations, but it might be worth opening trouble tickets if
it's not. :)
OTOH, I understand the cost that comes with maintaining special-cased
code for non-supporting implementations. It might not be worth it.
Still, I felt like sharing this, before I forget again. :)
Cheers,
Michael
;;; Example code:
(progn
(defclass shape () ())
(defclass circle (shape) ())
(defclass color () ())
(defclass orange (color) ())
(defclass mangenta (color) ())
(defclass label-type () ())
(defclass top-labeled (label-type) ())
(defclass bottom-labeled (label-type) ()))
#||
===> (class-direct-subclasses (find-class 'circle))
()
===> (defparameter *i1* (make-programmatic-instance '(circle orange
top-labeled)))
===> (defparameter *i2* (make-programmatic-instance '(circle mangenta
bottom-labeled)))
===> (defparameter *i3* (make-programmatic-instance '(circle orange
top-labeled)))
===> (class-direct-subclasses (find-class 'circle))
(#<Standard-Class (CIRCLE MAGENTA BOTTOM-LABELED) >
#<Standard-Class (CIRCLE ORANGE TOP-LABELED) >)
||#
More information about the Flexi-streams-devel
mailing list