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

defmethod and specializing on &key parameters.

42 views
Skip to first unread message

Daniel Pittman

unread,
Mar 28, 2002, 2:35:30 AM3/28/02
to
From my reading of the HyperSpec it seems that you cannot specialize a
method based on keyword arguments. Can someone confirm that this is,
indeed, a correct reading of the `defmethod' entry?

Thanks,
Daniel

--
If a man is pictured chopping off a woman's breast, it only gets a R rating,
but if, God forbid, a man is pictured kissing a woman's breast, it gets an X
rating. Why is violence more acceptable than tenderness?
-- Sally Struthers

Erik Naggum

unread,
Mar 28, 2002, 3:31:32 AM3/28/02
to
* Daniel Pittman

| From my reading of the HyperSpec it seems that you cannot specialize a
| method based on keyword arguments. Can someone confirm that this is,
| indeed, a correct reading of the `defmethod' entry?

This is explained in clause 7.6 Generic Functions and Methods in the
standard, specifically in 7.6.4 Congruent Lambda-lists for all Methods of
a Generic Function.

///
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.

Wolfhard Buß

unread,
Mar 28, 2002, 4:04:23 AM3/28/02
to
Daniel Pittman <dan...@rimspace.net> writes:

> From my reading of the HyperSpec it seems that you cannot specialize a
> method based on keyword arguments. Can someone confirm that this is,
> indeed, a correct reading of the `defmethod' entry?

Exactly the required parameters are specializable.
See CLHS 7.6.2 Introduction to Methods or the 'defmethod entry'.

--
"Das Auto hat keine Zukunft. Ich setze aufs Pferd." Wilhelm II. (1859-1941)

Tim Moore

unread,
Mar 28, 2002, 1:30:54 PM3/28/02
to
On Thu, 28 Mar 2002 18:35:30 +1100, Daniel Pittman <dan...@rimspace.net> wrote:
>From my reading of the HyperSpec it seems that you cannot specialize a
>method based on keyword arguments. Can someone confirm that this is,
>indeed, a correct reading of the `defmethod' entry?
>
>Thanks,
> Daniel

You can't specialize on keyword arguments, as others have said. If
you want to do that, a common idiom is to split your function into a
function that takes keyword arguments and a generic function called
with sensible defaults by the first function. For example, from McCLIM:

(defun read-gesture (&key
(stream *standard-input*)
timeout
peek-p
(input-wait-test *input-wait-test*)
(input-wait-handler *input-wait-handler*)
(pointer-button-press-handler
*pointer-button-press-handler*))
(stream-read-gesture stream
:timeout timeout
:peek-p peek-p
:input-wait-test input-wait-test
:input-wait-handler input-wait-handler
:pointer-button-press-handler
pointer-button-press-handler))

(defgeneric stream-read-gesture (stream
&key timeout peek-p
input-wait-test
input-wait-handler
pointer-button-press-handler))

Tim

0 new messages