Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about defmethod, call-next-method, and declarations

1 view
Skip to first unread message

Ken Anderson

unread,
Mar 23, 1996, 3:00:00 AM3/23/96
to
In article <82rav9y...@hawk.eecs.umich.edu> hu...@eecs.umich.edu (Michael Hucka) writes:

Is it correct to declare the arguments keyword1 and keyword2 as ignored? I.e.,

(defmethod foo ((arg1 some-class) &key (keyword1 'bar) (keyword2 'baz))
(declare (ignore keyword1 keyword2))
(call-next-method))

I'm wondering whether that will have the wrong behavior if the next method
actually does use those arguments. If they're not declared, of course, the
compiler will complain about unused arguments.

The arguments are not ignored since
(call-next-method)
is really the same as
(call-next-method arg1 :keyword1 keyword1 :keyword2 keyword2)

k

Bruno Haible

unread,
Mar 29, 1996, 3:00:00 AM3/29/96
to
Michael Hucka <hu...@eecs.umich.edu> asked:

>
> Is it correct to declare the arguments keyword1 and keyword2 as ignored? I.e.,
>
> (defmethod foo ((arg1 some-class) &key (keyword1 'bar) (keyword2 'baz))
> (declare (ignore keyword1 keyword2))
> (call-next-method))
>
> I'm wondering whether that will have the wrong behavior if the next method
> actually does use those arguments. If they're not declared, of course, the
> compiler will complain about unused arguments.

Ken Anderson <kand...@stout.bbn.com> wrote:
> The arguments are not ignored since
> (call-next-method)
> is really the same as
> (call-next-method arg1 :keyword1 keyword1 :keyword2 keyword2)

If there was a (setq keyword1 nil keyword2 nil) statement before the
(call-next-method), then the CL spec (dpANS p. 7-75) says that this wouldn't
affect the arguments passed to the next method. Hence the original
arguments are stored behind the scenes, and the method call roughly
looks like this:

(lambda (hidden-arg1 &rest hidden-rest)
(flet ((call-next-method ()
(apply *next-method* hidden-arg1 hidden-rest)))
(apply (lambda (arg1 &key (keyword1 'bar) (keyword2 'baz))
(declare (ignore keyword1 keyword2))
...
(call-next-method))
hidden-arg1 hidden-rest)))

Of course, the compiler will notice that `hidden-arg1' and `arg1' are
never setq'ed and hence use `hidden-arg1' instead of `arg1' in all places.
And it will warn if keyword1 and keyword2 are not explicitly used.


Bruno Haible email: <hai...@ilog.fr>
Software Engineer phone: +33-1-49083585

0 new messages