|
From: Hoehle, Joerg-C. <Joe...@t-...> - 2003-02-19 13:11:54
|
Hi,
I'm seeking help with CLOS. I want to define a slot that all instances =
of a class will share. This sounds like typical :allocation :class. But =
read on.
One of these special slots is supposed to contain a function (closure) =
that I want compiled at file-compilation time. Another will be set at =
run-time. Another will contain the lambda expression to compile at =
run-time and ought to be defined at file-compilation time as well.
I thought about the following macro to declare the code:
(define-analyse-line ((analyse durchsatz))
(incf (gethash key (analyse-top-table analyse)))
(princ #\; (analyse-outstream analyse)))
which would macroexpand to:
(let ((*columns-used* '()))
(setf (analyse-line-function (find-class 'durchsatz))
(lambda (analyse .line. .start-positions. .stop-positions.)
(macrolet ((log-line-universal-time () ;TODO? flet
(or (analyse-universal-time analyse) #))
(log-line-sql-time ()
(format nil #)))
body...))
(setf (analyse-used-columns #) *columns-used*)))
and here's something which cannot work
(defmacro define-analyse-line ((var class) &body body)
(let* ((*precompile* nil)
(*columns-used* '()))
(setf (analyse-line-function (find-class ',class))
(lambda (,var .line. .start-positions. .stop-positions.)
,@body))
(setf (analyse-line-lambda (find-class ',class)) ',body)
(setf (analyse-used-columns (find-class ',class)) *columns-used*)))
The reason it cannot work is that analyse-line-lambda and =
-line-function are not typically slots of (find-class 'analyse), but =
rather shared slots of each instance.
Need I got MOP here or is that overshoot? Am I misguided?
Maybe all I need is a wrapper around defclass and some initform =
instead?
This could become weird as well, since the closure body may reference =
slots to be defined in this same DEFCLASS form (e.g. analyse-top-table =
above).
Thanks for your help,
J=F6rg H=F6hle.
|