amit phalgune writes:
> Hi David,
> Thanks for the reply. Do you mean that I change the progn to
> There is just one defmethod with progn in the source I have.
> But I still have a doubt. I have basically not understood what the
> defgeneric code is doing.
> It all seems to be related to classes and instances and the methods
> associated with it..
> But I am extremely unclear and confused abt it. I tried to look on the =
> for the related documents.. but since I am not aware of OO lisp, or for
> that matter even normal LISP ( i have just begun coding in LISP)..=20
One essential resource for Common-Lisp programmers is obviously: The
Common-Lisp HyerSpec at:
There is a chapter on Objects:
See also: http://www.cliki.org/ for links.
> I am not able to understand what that code is supposed to do and why
> and what happens if we replace progn with (call-next-method)
> I will be extremely grateful if you can kindly explain it to me...
defgeneric just defines an interface to a generic operation. Once
defined, the system will know that any function call with this
function name should be dispatched depending on the type of the
arguments, selecting a method.
Introduction to Generic Functions:
Since there may be multiple inheritance of objects, several method may
apply for on generic call. The question is then in what order to call
the various methods.
In other object oriented languages, usually only the most specific
method is invoked (but with multiple inheritance, there may be no most
specific method). So defgeneric allow you to specify a default order
for the method invocation, and you can do it when defining each method
> > > (defgeneric destroy (a) (:method-combination progn))
Since you're implementation does not know the progn method
combination, you may choose another order yourself. Check the various
destroy methods you have and determine in which order they must be
run. If they have to be run from the most specific first to the less
specific last, it's :before. Otherwise, it's :after. If the order is
more complicated (unlikely since it was specified progn), you would
use :arround, and in each method, you could specify when to call the
less specific method with (call-next-method).
So, removing (:method-combination progn) from the defgeneric,
and adding :before to the defmethod destroy,=20
could be the solution:
(defgeneric destroy (a))
(defmethod destroy :before ((a class-1) #| ... |# )
(defmethod destroy :before ((a class-2) #| ... |# )
Do not adjust your mind, there is a fault in reality.