From: Thaddeus L. Olczyk
Subject: Problem with function arguments.
Date: 
Message-ID: <3b26544c.480081562@nntp.interaccess.com>
I'm having trouble in emacs/eieio writing a certain method
of a class I wrote:random-access-stack.
I've tried to do this:
>(defmethod show-ras((x random-access-stack) &key (do-print #'my-print))
with the idea that do-print is a keyword.

With this particular version I get the error message:
>Wrong number of arguments: (lambda (x &key do-print) (interactive) ...

I've tried other variations.
>(defmethod show-ras((x random-access-stack) &key do-print #'my-print)
>(defmethod show-ras((x random-access-stack) &key ((do-print #'my-print)))
I've also checked the books that I have.
None seem to give any clear answer. Cananyone help?

From: Barry Margolin
Subject: Re: Problem with function arguments.
Date: 
Message-ID: <SZsV6.15$5G3.337@burlma1-snr2>
In article <··················@nntp.interaccess.com>,
Thaddeus L. Olczyk <······@interaccess.com> wrote:
>I'm having trouble in emacs/eieio writing a certain method
>of a class I wrote:random-access-stack.
>I've tried to do this:
>>(defmethod show-ras((x random-access-stack) &key (do-print #'my-print))
>with the idea that do-print is a keyword.
>
>With this particular version I get the error message:
>>Wrong number of arguments: (lambda (x &key do-print) (interactive) ...

Emacs Lisp doesn't support keyword arguments.  EIEIO adds OOP, but uses the
built-in function definition mechanism to implement them.  Notice that it
defined an ordinary lambda expression, with &key as an argument name.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Thomas F. Burdick
Subject: Re: Problem with function arguments.
Date: 
Message-ID: <xcvg0d5bjvu.fsf@apocalypse.OCF.Berkeley.EDU>
Barry Margolin <······@genuity.net> writes:

> In article <··················@nntp.interaccess.com>,
> Thaddeus L. Olczyk <······@interaccess.com> wrote:
> >I'm having trouble in emacs/eieio writing a certain method
> >of a class I wrote:random-access-stack.

> >I've tried to do this:
> >>(defmethod show-ras((x random-access-stack) &key (do-print #'my-print))
> >with the idea that do-print is a keyword.
> >
> >With this particular version I get the error message:
> >>Wrong number of arguments: (lambda (x &key do-print) (interactive) ...
> 
> Emacs Lisp doesn't support keyword arguments.  EIEIO adds OOP, but uses the
> built-in function definition mechanism to implement them.  Notice that it
> defined an ordinary lambda expression, with &key as an argument name.

The way to do this is to use the `destructuring-bind' provided by the
`cl' package:
  (defun foo (somearg &rest cl-keys)
    (destructuring-bind
        (&key foo bar baz)
        cl-keys
      ...))

or `defun*' which does this for you:
  (defun* foo (somearg &key foo bar baz)
    ...)

I'd highly reccomend defining yourself a `defmethod*' (which is what I
use when programming eieio):
  (defmacro defmethod (name args &rest body)
    "(defmethod* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
  Like normal `defmethod', except ARGLIST allows full Common Lisp conventions,
  and BODY is implicitly surrounded by (block NAME ...)."
    (let* ((res (cl-transform-lambda (cons args body) name))
  	 (form (list* 'defmethod name (cdr res))))
      (if (car res) (list 'progn (car res) form) form)))
From: Thaddeus L. Olczyk
Subject: Re: Problem with function arguments.
Date: 
Message-ID: <3b2784be.492483640@nntp.interaccess.com>
On 12 Jun 2001 12:03:49 -0700, ···@apocalypse.OCF.Berkeley.EDU (Thomas
F. Burdick) wrote:

>Barry Margolin <······@genuity.net> writes:
>
>> In article <··················@nntp.interaccess.com>,
>> Thaddeus L. Olczyk <······@interaccess.com> wrote:
>> >I'm having trouble in emacs/eieio writing a certain method
>> >of a class I wrote:random-access-stack.
>
>> >I've tried to do this:
>> >>(defmethod show-ras((x random-access-stack) &key (do-print #'my-print))
>> >with the idea that do-print is a keyword.
>> >
>> >With this particular version I get the error message:
>> >>Wrong number of arguments: (lambda (x &key do-print) (interactive) ...
>> 
>> Emacs Lisp doesn't support keyword arguments.  EIEIO adds OOP, but uses the
>> built-in function definition mechanism to implement them.  Notice that it
>> defined an ordinary lambda expression, with &key as an argument name.
>
>The way to do this is to use the `destructuring-bind' provided by the
>`cl' package:
>  (defun foo (somearg &rest cl-keys)
>    (destructuring-bind
>        (&key foo bar baz)
>        cl-keys
>      ...))
>
>or `defun*' which does this for you:
>  (defun* foo (somearg &key foo bar baz)
>    ...)
>
>I'd highly reccomend defining yourself a `defmethod*' (which is what I
>use when programming eieio):
>  (defmacro defmethod (name args &rest body)
>    "(defmethod* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
>  Like normal `defmethod', except ARGLIST allows full Common Lisp conventions,
>  and BODY is implicitly surrounded by (block NAME ...)."
>    (let* ((res (cl-transform-lambda (cons args body) name))
>  	 (form (list* 'defmethod name (cdr res))))
>      (if (car res) (list 'progn (car res) form) form)))
I actually asked about this a short while ago and got as a response (
it was in a unrelated matter ) that  defun* had to be used because 
one could not redefine ( without breaking a lot of code ) defun
because it was a part of the elisp core, but that defmethod was
defined correctly because it is not a part of the elisp core.
Thanks for the sugestion ( I presume that you mean (defmacro
defmethod* above ). Since I'm not that adroit at lisp I'll have to
take a closer look at it.
From: Thomas F. Burdick
Subject: Re: Problem with function arguments.
Date: 
Message-ID: <xcv66e0ta0k.fsf@conquest.OCF.Berkeley.EDU>
······@interaccess.com (Thaddeus L. Olczyk) writes:

> >I'd highly reccomend defining yourself a `defmethod*' (which is what I
> >use when programming eieio):
> >  (defmacro defmethod (name args &rest body)
               ^- oops, "defmethod*"
> >    "(defmethod* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
> >  Like normal `defmethod', except ARGLIST allows full Common Lisp conventions,
> >  and BODY is implicitly surrounded by (block NAME ...)."
> >    (let* ((res (cl-transform-lambda (cons args body) name))
> >  	 (form (list* 'defmethod name (cdr res))))
> >      (if (car res) (list 'progn (car res) form) form)))
>
> I actually asked about this a short while ago and got as a response (
> it was in a unrelated matter ) that  defun* had to be used because 
> one could not redefine ( without breaking a lot of code ) defun
> because it was a part of the elisp core, but that defmethod was
> defined correctly because it is not a part of the elisp core.

If you check Barry Margolin's response, you'll see that a defmethod like
 (defmethod foo ((foo some-class) &key bar baz) ...)
expands into (lambda (foo &key bar baz) ...) and doesn't use the `cl'
machinery, unfortunately.  Come to think of it, I should submit this
as a bug to the eieio maintainer.  BTW, my definition above for
`defmethod*' won't work.  I'll post one tomorrow that will (I don't
have access to eieio or my personal `defmethod*' where I'm sitting).

I call it defmethod* in my code to parallel defun* and defmacro*, and
to not confuse normal eieio users.  Maybe it's unnecessary, but it
also helps me to remember I'm using elisp, with eieio's silly
single-dispatch methods, and not the full power of CLOS :).