[Openmcl-devel] GF invocation protocol

Vyacheslav Akhmechet coffeemug at gmail.com
Tue Sep 11 22:22:06 PDT 2007


On 9/11/07, Slava Akhmechet <coffeemug at gmail.com> wrote:
> Ok. In this case, how can I obtain the function associated with a
> funcallable-instance in OpenMCL (from what I understand there is no
> MOP recommendation for doing it)? I'm basically looking for the
> opposite of set-funcallable-instance-function. I might be able to
> achieve what I want via changing it on affected generic functions
> directly.
Ok, so I did some browsing in OpenMCL codebase and I think I was able
to answer my own questions.

I can obtain the actual function from a generic function object via:
(ccl::uvref #'gf ccl::gf.dcode)

The function it returns requires an extra argument - the dispatch
table. I can get that via:
(ccl::%gf-dispatch-table #'gf)

With this information I can set-funcallable-instance on the generic
function to my own function, modify the arguments as I wish (which was
my intent) and pass them to OpenMCL standard dispatch mechanism:

(defmethod test (a b) (+ a b))

(let ((dfun (ccl::uvref #'test ccl::gf.dcode))
       (dt (ccl::%gf-dispatch-table #'test)))
  (set-funcallable-instance-function #'test
                                                         (lambda (a1 a2)
                                                           (funcall
dfun dt (1+ a1) (1+ a2)))))

(test 1 1) => 4

This works very nicely. My only concern is the following quote from
features.txt of the CloserMop project regarding OpenMCL: "Likewise,
the second parameter to set-funcallable-instance-function cannot be a
closure, but only a "pure" function/thunk"[1]. The code above seems to
work very well for me. Is this quote from Closer project outdated or
this is still something to worry about?

[1] http://common-lisp.net/project/closer/repos/closer-mop/features.txt

Regards,
Slava Akhmechet



More information about the Openmcl-devel mailing list