Subject: [clisp-list] ANSI compatibility question

From: "David E. Young" <[email-masked]>
Date: Tue, 3 Apr 2001 15:46:38 -0400

Greetings. Ok, let's see if I can clear this up.

Given the following simplified code fragment:

(defclass rule ()
  ((name :initarg :name
         :initform nil
         :reader get-name)))

(defmethod initialize-instance :after ((self rule) &key (directives nil))
  ...)

(defun make-rule (name engine &key (doc-string nil)
                  (directives nil) (source nil))
  (make-instance 'rule :name name :directives directives))

Note the addition of an initialisation argument in
initialize-instance's lambda list.

With the above, CLISP fails at runtime with:

*** - EVAL/APPLY: keyword :NAME is illegal for #<COMPILED-CLOSURE #:COMPILED-FORM-129-1>. The possible keywords are (:DIRECTIVES)
1. Break LISA[5]>

Now, if I read the CLHS correctly it seems that this should work. And
indeed, ACL, LispWorks and CMUCL accept it [ but, after my last
posting I'm no longer sure how reliable an argument that is. ]

From CLHS section 7.1.2 Declaring the Validity of Initialization Arguments:

* Initialization arguments that fill slots are declared as valid by
  the :initarg slot option to defclass...

* Initialization arguments that supply arguments to methods are
  declared as valid by defining those methods. The keyword name of
  each keyword parameter specified in the method's lambda list becomes
  an initialization argument for all classes for which the method is
  applicable...

Please help me clear this up.

Regards,

-- 
-----------------------------------------------------------------
David E. Young
Fujitsu Network Communications  (defun real-language? (lang)
([email-masked])           (eq lang 'LISP))

"But all the world understands my language."
  -- Franz Joseph Haydn (1732-1809)

---

From: Sam Steingold <[email-masked]>
Date: 03 Apr 2001 15:07:55 -0500

> * In message <[email-masked]>
> * On the subject of "[clisp-list] ANSI compatibility question"
> * Sent on Tue, 3 Apr 2001 15:46:38 -0400
> * Honorable "David E. Young" <[email-masked]> writes:
>
> (defclass rule ()
>   ((name :initarg :name
>          :initform nil
>          :reader get-name)))
> 

CLISP tries to call your `initialize-instance' :after method and fails -
it does not take :name args.
If you write

(defmethod initialize-instance :after ((self rule) &key (directives nil)
                                       &allow-other-keys)
   ...)

it should work.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
You can have it good, soon or cheap.  Pick two...

---

From: "David E. Young" <[email-masked]>
Date: Tue, 3 Apr 2001 16:13:54 -0400

>>>>> "Sam" == Sam Steingold <[email-masked]> writes:

Sam> CLISP tries to call your `initialize-instance' :after method and
Sam> fails - it does not take :name args.  If you write

Sam> (defmethod initialize-instance :after ((self rule) &key
Sam> (directives nil) &allow-other-keys) ...)

Sam> it should work.

Yes, but &allow-other-keys in that situation disables keyword argument
checking, which is not what I want.

So, what is the correct, ANSI behavior?

Regards,

---

From: Sam Steingold <[email-masked]>
Date: 03 Apr 2001 16:27:34 -0500

> * In message <[email-masked]>
> * On the subject of "Re: [clisp-list] ANSI compatibility question"
> * Sent on Tue, 3 Apr 2001 16:13:54 -0400

Please see Issue INITIALIZATION-FUNCTION-KEYWORD-CHECKING Writeup.
This is the intended behavior.

> So, what is the correct, ANSI behavior?

I believe CLISP is correct here.

I don't think that any error checking can actually be done here: the
same args which were given to `initialize-instance' will be passed over
to the `initialize-instance' :after method, so all `initialize-instance'
methods must take all the arguments that the main `initialize-instance'
takes.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Trespassers will be shot.  Survivors will be SHOT AGAIN!