Hello.
When I compile the following object-oriented code in SBCL, the last
method gives a warning ":EXPONENT2 is not a known argument keyword."
The method executes correctly, but I wonder why the warning. I've
grown accustomed to warnings being a very good diagnostic of my coding
errors, so I'm a bit paranoid of them. Are my declarations
incomplete?
Briefly, I have a base class with its method (and an empty &key
argument list), and a superclass with a method that over-rides the
base class method and has a keyword parameter. I get the warning when
the superclass method is compiled.
Thank you,
Mirko
(in-package :cl-user)
(defclass operation ()
((dummy :initform nil :accessor dummy)))
(defclass power (operation)
((exponent :initform 2
:accessor exponent)))
(defgeneric execute (class operand &key)
(:documentation "Execute operation"))
(defmethod execute ((this operation) operand &key)
operand)
(defmethod execute ((this power) operand &key exponent2)
(expt operand (or exponent2 (exponent this))))
(defgeneric example (this)
(:documentation "Example of execute operation"))
;; Will compile with warning ":EXPONENT2 is not a known argument
keyword."
(defmethod example ((this power))
(execute this 2 :exponent2 3))
From: Pascal J. Bourguignon
Subject: Re: "not a known argument keyword": method precedence problem or incomplete declarations?
Date:
Message-ID: <87y71i8srm.fsf@hubble.informatimago.com>
·············@gmail.com writes:
> Hello.
>
> When I compile the following object-oriented code in SBCL, the last
> method gives a warning ":EXPONENT2 is not a known argument keyword."
>
> The method executes correctly, but I wonder why the warning. I've
> grown accustomed to warnings being a very good diagnostic of my coding
> errors, so I'm a bit paranoid of them. Are my declarations
> incomplete?
>
> Briefly, I have a base class with its method (and an empty &key
> argument list), and a superclass with a method that over-rides the
> base class method and has a keyword parameter. I get the warning when
> the superclass method is compiled.
>
> Thank you,
>
> Mirko
>
> (in-package :cl-user)
>
> (defclass operation ()
> ((dummy :initform nil :accessor dummy)))
>
> (defclass power (operation)
> ((exponent :initform 2
> :accessor exponent)))
>
> (defgeneric execute (class operand &key)
You need:
(defgeneric execute (class operand &key &allow-other-keys)
> (:documentation "Execute operation"))
>
> (defmethod execute ((this operation) operand &key)
It would be more prudent to:
(defmethod execute ((this operation) operand &key &allow-other-keys)
> operand)
>
> (defmethod execute ((this power) operand &key exponent2)
and here too:
(defmethod execute ((this operation) operand &key exponent2 &allow-other-keys)
> (expt operand (or exponent2 (exponent this))))
>
> (defgeneric example (this)
> (:documentation "Example of execute operation"))
>
> ;; Will compile with warning ":EXPONENT2 is not a known argument
> keyword."
> (defmethod example ((this power))
> (execute this 2 :exponent2 3))
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Specifications are for the weak and timid!"
On Sep 23, 5:19 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> ·············@gmail.com writes:
> > Hello.
>
> > When I compile the following object-oriented code in SBCL, the last
> > method gives a warning ":EXPONENT2 is not a known argument keyword."
>
> > The method executes correctly, but I wonder why the warning. I've
> > grown accustomed to warnings being a very good diagnostic of my coding
> > errors, so I'm a bit paranoid of them. Are my declarations
> > incomplete?
>
> > Briefly, I have a base class with its method (and an empty &key
> > argument list), and a superclass with a method that over-rides the
> > base class method and has a keyword parameter. I get the warning when
> > the superclass method is compiled.
>
> > Thank you,
>
> > Mirko
>
> > (in-package :cl-user)
>
> > (defclass operation ()
> > ((dummy :initform nil :accessor dummy)))
>
> > (defclass power (operation)
> > ((exponent :initform 2
> > :accessor exponent)))
>
> > (defgeneric execute (class operand &key)
>
> You need:
>
> (defgeneric execute (class operand &key &allow-other-keys)
>
> > (:documentation "Execute operation"))
>
> > (defmethod execute ((this operation) operand &key)
>
> It would be more prudent to:
>
> (defmethod execute ((this operation) operand &key &allow-other-keys)
>
> > operand)
>
> > (defmethod execute ((this power) operand &key exponent2)
>
> and here too:
>
> (defmethod execute ((this operation) operand &key exponent2 &allow-other-keys)
>
> > (expt operand (or exponent2 (exponent this))))
>
> > (defgeneric example (this)
> > (:documentation "Example of execute operation"))
>
> > ;; Will compile with warning ":EXPONENT2 is not a known argument
> > keyword."
> > (defmethod example ((this power))
> > (execute this 2 :exponent2 3))
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
>
> "Specifications are for the weak and timid!"
Thank you!