Hi,
this might be obvious but I'm pretty new to CL so I do not know how to
do it
For easy maintenance I wanted to do the following
defconstant Vec (class-name Vec2D) ;Vec2D is a class defined
elsewhere
(defmethod bla ((v Vec) b)
t)
As I understand it Vec does not get evaluated in the method definition
because defmethod is a macro. Thus I get an error becaus a class with
the name of Vec does not exist. But how can I get around this
limitation, i.e.: How can I have methods that depend on class names in
variables?
Thx Till
In article <·················@stud.uni-goettingen.de>,
Till Kranz <·······@gmx.de> wrote:
>Hi,
>
>this might be obvious but I'm pretty new to CL so I do not know how to
>do it
>
>For easy maintenance I wanted to do the following
>
>defconstant Vec (class-name Vec2D) ;Vec2D is a class defined
>elsewhere
>
>(defmethod bla ((v Vec) b)
> t)
>
>As I understand it Vec does not get evaluated in the method definition
>because defmethod is a macro. Thus I get an error becaus a class with
>the name of Vec does not exist. But how can I get around this
>limitation, i.e.: How can I have methods that depend on class names in
>variables?
The "right" way is to use the Meta-Object Protocol to create the method.
But a crude solution is:
(eval `(defmethod ((v ,Vec) b) t))
--
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.
Till Kranz <··········@stud.uni-goettingen.de> writes:
> defconstant Vec (class-name Vec2D) ;Vec2D is a class defined
> elsewhere
>
> (defmethod bla ((v Vec) b)
> t)
>
> As I understand it Vec does not get evaluated in the method definition
> because defmethod is a macro. Thus I get an error becaus a class with
> the name of Vec does not exist. But how can I get around this
> limitation, i.e.: How can I have methods that depend on class names in
> variables?
Barry's answered your exact question. But maybe consider
(setf (find-class 'vec) (find-class 'vec2d))
(defmethod bla ((v vec) b)
t)
which is portable Common Lisp (under the assumption that the VEC2D
class already exists, of course.
Christophe
--
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)