I am trying tu modify the behaviour of a method like this :
(defgeneric foo (this &rest args))
(defmethod foo (this &rest args)
(cons this args))
(defclass bar () ())
(defmethod foo ((this bar) &rest args)
(apply 'call-next-method :bar args))
Un fortunately this does not work :
(foo (make-instance 'bar) 1 2)
Error: attempt to call `CALL-NEXT-METHOD' which is an undefined
function.
[condition type: UNDEFINED-FUNCTION]
How should I do such a modification of arguments to CALL-NEXT-METHOD?
--
Kim Minh.
http://www.kim-minh.com/
From: Pascal Costanza
Subject: Re: How do you use APPLY with CALL-NEXT-METHOD ?
Date:
Message-ID: <4ihg5eF3qb79U1@individual.net>
Kim Minh Kaplan wrote:
> I am trying tu modify the behaviour of a method like this :
>
> (defgeneric foo (this &rest args))
>
> (defmethod foo (this &rest args)
> (cons this args))
>
> (defclass bar () ())
>
> (defmethod foo ((this bar) &rest args)
> (apply 'call-next-method :bar args))
>
> Un fortunately this does not work :
>
> (foo (make-instance 'bar) 1 2)
>
> Error: attempt to call `CALL-NEXT-METHOD' which is an undefined
> function.
> [condition type: UNDEFINED-FUNCTION]
>
> How should I do such a modification of arguments to CALL-NEXT-METHOD?
If you apply or funcall a function by its quoted name, like you do when
you say (apply 'call-next-method ...), Lisp attempts to find a global
definition of that function, as if it were defined by defun or defgeneric.
However, call-next-method is typically implemented as a local function
(as if by flet or labels), so (apply 'call-next-method ...) cannot see
this local function. You should instead call (apply #'call-next-method
...), which will look up the function locally.
I hope this helps.
Pascal
--
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
Pascal Costanza wrote:
> If you apply or funcall a function by its quoted name, like you do when
> you say (apply 'call-next-method ...), Lisp attempts to find a global
> definition of that function, as if it were defined by defun or defgeneric.
>
> However, call-next-method is typically implemented as a local function
> (as if by flet or labels), so (apply 'call-next-method ...) cannot see
> this local function. You should instead call (apply #'call-next-method
> ...), which will look up the function locally.
>
> I hope this helps.
Ah, silly me, I should have thought about it. Works now, thank you.
--
Kim Minh
http://www.kim-minh.com/