Menu

#733 Accepted and rejected key arguments for defgeneric/defmethod. (7.6.4)

open
nobody
None
5
2018-03-05
2018-03-05
No
(defgeneric f (val &key p1))

(defmethod f ((val (eql 1)) &key p1 p2)
  (print p1)
  (print p2))

(defmethod f ((val (eql 2)) &key p1 p3)
  (print p1)
  (print p3))

(f 1 :p2 22)
(f 1 :p3 22)
(f 1 :p4 22)

Compiling the above file signals no error.
Loading the above file signals an error on the use of :p3 (and of :p4 too).

My reading of sections 7.6.4 and 7.6.5, notably point 4 of 7.6.4 is that :p3 should be accepted without error, and :p4 should signal an error.

Therefore it seems to be we have a conformance issue with :p3.
(sbcl and ccl don't signal an error for :p3, and signal an error for :p4, which seems to be the conforming thing to do).

Section 7.6.4, point 4:

    4. If the generic function lambda list mentions &key, each method
       must accept all of the keyword names mentioned after &key, either
       by accepting them explicitly, by specifying &allow-other-keys, or
       by specifying &rest but not &key.

       Each method can accept additional keyword arguments of its own.

       The checking  of the  validity of  keyword names  is done  in the
       generic function, not in each method.

       A method is invoked as if the keyword argument pair whose name is
       :allow-other-keys and whose value is true were supplied, though
       no such argument pair will be passed.

Section 7.6.5:

     If a generic function is passed a keyword argument that no
     applicable method accepts, an error should be signaled; see Section
     3.5 (Error Checking in Function Calls).    

Discussion


Log in to post a comment.