From: Ralitsa
Subject: CLOS problem ---urgent
Date: 
Message-ID: <96957557.0305211158.7bd5e335@posting.google.com>
Hello to all of you! I have the following problem: suppose I have defined
a class Geometric

 (defclass Geometric ()
   ((color :accessor color :initform 'black))
   (:documentation "The basic class for all graphical objects.Slot:
Color")) 

I want to define a before and after methods that are suppose to
show the color right before/after changing it. I tried the following code:

(defgeneric set_color ((new_color list) (obj Geometric))
   (:method ((new_color list)(obj Geometric)) (setf (color obj) new_color)
))
 (defmethod set_color :before ((new_value list) (obj Geometric))
  (print 'before (color obj))
  )

 but the interpreter comes up with an error:


 USER(37):  (set_color 'black g) Error: No methods applicable for generic
function
       #<STANDARD-GENERIC-FUNCTION SET_COLOR> with args
       (BLACK #<GEOMETRIC @ #x2039cd0a>) of classes (SYMBOL GEOMETRIC)
  [condition type: PROGRAM-ERROR]


 Any idea why or where is the mistake?
Thank you in advance...

From: Thomas A. Russ
Subject: Re: CLOS problem ---urgent
Date: 
Message-ID: <ymir86rnb6v.fsf@sevak.isi.edu>
···@abv.bg (Ralitsa) writes:

> (defgeneric set_color ((new_color list) (obj Geometric))
>    (:method ((new_color list)(obj Geometric)) (setf (color obj) new_color)
> ))
>... 
>  but the interpreter comes up with an error:
> 
> 
>  USER(37):  (set_color 'black g) Error: No methods applicable for generic
> function
>        #<STANDARD-GENERIC-FUNCTION SET_COLOR> with args
>        (BLACK #<GEOMETRIC @ #x2039cd0a>) of classes (SYMBOL GEOMETRIC)
>   [condition type: PROGRAM-ERROR]
> 
>  Any idea why or where is the mistake?
> Thank you in advance...

Well, you could start by looking closely at what the error message is
tellin you and comparing it with the generic function that you wrote.

The error clearly says that it cannot find a method for arguments of
type (SYMBOL GEOMETRIC).  At this point you should ask yourself if you
have defined any such method.  Looking at the DEFGENERIC form that you
showed us, it doesn't appear to be the case.  You have defined a method
on argument types (LIST GEOMETRIC), and a symbol like 'BLACK is not of
type LIST.


-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Henrik Motakef
Subject: Re: CLOS problem ---urgent
Date: 
Message-ID: <87d6icdppu.fsf@interim.henrik-motakef.de>
···@abv.bg (Ralitsa) writes:

> I want to define a before and after methods that are suppose to
> show the color right before/after changing it. I tried the following code:
>
> (defgeneric set_color ((new_color list) (obj Geometric))
>    (:method ((new_color list)(obj Geometric)) (setf (color obj) new_color)
> ))
>  (defmethod set_color :before ((new_value list) (obj Geometric))
>   (print 'before (color obj))
>   )

First of all, it would probably be better style to call the gf
something like (setf color), or at least set-color.

>  but the interpreter comes up with an error:
>
>
>  USER(37):  (set_color 'black g) Error: No methods applicable for generic
> function
>        #<STANDARD-GENERIC-FUNCTION SET_COLOR> with args
>        (BLACK #<GEOMETRIC @ #x2039cd0a>) of classes (SYMBOL GEOMETRIC)
>   [condition type: PROGRAM-ERROR]

You pass the symbol black as the first argument, but you methods
expect lists. Symbols are not lists, obviously.

hth
Henrik
From: Kenny Tilton
Subject: Re: CLOS problem ---urgent
Date: 
Message-ID: <3ECC3B15.3050608@nyc.rr.com>
Ralitsa wrote:
> Hello to all of you! I have the following problem: suppose I have defined
> a class Geometric
> 
>  (defclass Geometric ()
>    ((color :accessor color :initform 'black))
>    (:documentation "The basic class for all graphical objects.Slot:
> Color")) 
> 
> I want to define a before and after methods that are suppose to
> show the color right before/after changing it. 

You could just:

(defmethod (setf color) :before (new-color (self geometric))
   (print `(new-color ,new-color for ,self)))


-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
From: Barry Margolin
Subject: Re: CLOS problem ---urgent
Date: 
Message-ID: <aT4za.4$Kf1.214@paloalto-snr1.gtei.net>
In article <····························@posting.google.com>,
Ralitsa <···@abv.bg> wrote:
>(defgeneric set_color ((new_color list) (obj Geometric))
>   (:method ((new_color list)(obj Geometric)) (setf (color obj) new_color)
>))
> (defmethod set_color :before ((new_value list) (obj Geometric))
>  (print 'before (color obj))
>  )
>
> but the interpreter comes up with an error:
>
>
> USER(37):  (set_color 'black g) Error: No methods applicable for generic
>function
>       #<STANDARD-GENERIC-FUNCTION SET_COLOR> with args
>       (BLACK #<GEOMETRIC @ #x2039cd0a>) of classes (SYMBOL GEOMETRIC)
>  [condition type: PROGRAM-ERROR]

You defined a method whose first argument is specialized on LIST.  But when
you called it, you passed a symbol, and never defined a method specialized
on this.

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, 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.