[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New g-wrap supported in guile-gtk--rotty-0.1!
From: |
Andy Wingo |
Subject: |
Re: New g-wrap supported in guile-gtk--rotty-0.1! |
Date: |
Mon, 19 Jan 2004 20:09:58 +0200 |
On Thu, 2003-12-04 at 02:25, Kevin Ryde wrote:
> I wonder if some lazy initializing would be possible, like catch a
> failed method dispatch and add only at that time. (But my ignorance
> of goops is pretty profound, so maybe it's not feasible.)
This is really a direct response to Andreas' question a couple days ago,
which I have read but don't have on my laptop...
I think I said something like make `add-method' cache methods, only
adding them when `no-method' is called. We can look at the GOOPS manual
(goops.info) to see what I mean.
`Method Definition Internals' states that after ensuring the generic and
creating the method, that the method is added to the generic via the
generic `add-method!'. If the generics we create are actually subclasses
of <generic>, we can specify `add-method!' to just keep the method in a
holding pen of sorts. Which is to say,
(define-class <guile-gnome-generic> (<generic>)
(temp-methods :init-value '()))
(define-method (add-method! (generic <guile-gnome-generic>)
(method <method>))
;; Note we don't call next-method
(slot-set! generic 'temp-methods
(cons method (slot-ref generic 'temp-methods))))
Then, as specified in `Handling Invocation Errors',
(define-method (no-method (generic <guile-gnome-generic>) args)
(if (slot-ref generic 'temp-methods)
(begin
(for-each
some-voodoo-to-get-the-original-add-method!
(slot-ref generic 'temp-methods))
(slot-set! generic 'temp-methods #f)
(apply generic args))
(next-method)))
That would delay the work of add-methods! while still keeping the
generic's symbol around for tab-completion and the like. The only bad
side is you couldn't query what methods exist on the generic without
invoking it. The MOP could be extended to turn generic-function-methods
into a generic function, though.
--
Andy Wingo <address@hidden>