[Openmcl-devel] GF invocation protocol
coffeemug at gmail.com
Mon Sep 17 21:40:04 PDT 2007
On 9/12/07, Gary Byers <gb at clozure.com> wrote:
> If you wanted to pursue this, it might be helpful to know that
> ccl::%%one-arg-dcode expects the arguments (DT ARG)
> ccl::%%1st-two-arg-dcode expects the arguments (DT ARG0 ARG1)
> All other dcode functions expect the arguments (DT ARGS)
> I think that this all qualifies as "low-level gunk".
Thank you, this was very useful. Here's a follow up, in case anyone is
I've spent the past week porting my code to various implementations.
OpenMCL actually turned out to be pretty easy. I first defined
compute-discriminating-function method on standard-generic-function.
It doesn't hurt because OpenMCL never calls it and it provides
functionality that allows easy specialization of
compute-discriminating-function on subclasses of
(defmethod compute-discriminating-function ((gf standard-generic-function))
(let ((std-dfun (ccl::%gf-dcode gf))
(dt (ccl::%gf-dispatch-table gf)))
(lambda (&rest args)
(case (ccl::function-name std-dfun)
(ccl::%%one-arg-dcode (apply std-dfun dt args))
(ccl::%%1st-two-arg-dcode (apply std-dfun dt args))
(t (funcall std-dfun dt args))))))
This function can be optimized (no need to keep the branching within
the returned lambda, it can be pushed outside) and ccl::function-name
can probably fail at some point, but the code conveys the basic idea
(and so far works well).
I then specialized :after methods of add-method, remove-method,
initialize-instance (for GFs and methods), and reinitialize-instance
(also for GFs and methods) to call set-funcallable-instance on the GF
and set it to the result of compute-discriminating-function called on
the GF. I do these specializations on my subclasses of
As part of my application I specialize compute-discriminating-function
on my custom generic functions and this code works exactly the same
way as it does on other implementations - it can close over
(call-next-method) and later invoke that function. Effectively the
default specialization of compute-discriminating-function on
standard-generic-function acts as a generator of a trampoline.
Hope this makes sense and people find it useful.
More information about the Openmcl-devel