From: charlieb
Subject: question about (class-name (class-of var))
Date: 
Message-ID: <2iqtleFqg71rU1@uni-berlin.de>
Hi,
	I'm having a little problem with this function or rather the flet part 
of it. The two print statements, which should be the same return 
WAR-BOID-<COLOUR> and SYMBOL for the main body and the flet 
respectively. Can you help me with this 'cause I can't figure it out.

Cheers
Charlieb

(defun boid-war (boid)
   "The idea is that if there are more enemy boids than friends within 
the zone this boids should change sides."
   (flet ((enemy-type (b)
		       (if (eq (print (class-name (class-of b)))
			       'war-boid-red)
			   'war-boid-blue
			 'war-boid-red)))
     (let ((all-nears (near-boids boid *boids* *comfort-dist*)))
       (unless (null all-nears)
	(let ((num-enemy-boids (length (boids-of-type
					all-nears
					(enemy-type
					 (class-name (class-of boid))))))
	      (num-friendly-boids (length (boids-of-type
					   all-nears
					   (class-name (class-of boid))))))
	  (when (> num-enemy-boids num-friendly-boids)
	    (print (class-name (class-of boid)))
	    (change-class boid (enemy-type boid))))))))

From: charlieb
Subject: Re: question about (class-name (class-of var))
Date: 
Message-ID: <2ir1nlFq9nc3U1@uni-berlin.de>
Ok so I figured it out. I feel stupid now, but what's new.

Cheers
Charlieb

charlieb wrote:

> Hi,
>     I'm having a little problem with this function or rather the flet 
> part of it. The two print statements, which should be the same return 
> WAR-BOID-<COLOUR> and SYMBOL for the main body and the flet 
> respectively. Can you help me with this 'cause I can't figure it out.
> 
> Cheers
> Charlieb
> 
> (defun boid-war (boid)
>   "The idea is that if there are more enemy boids than friends within 
> the zone this boids should change sides."
>   (flet ((enemy-type (b)
>                (if (eq (print (class-name (class-of b)))
>                    'war-boid-red)
>                'war-boid-blue
>              'war-boid-red)))
>     (let ((all-nears (near-boids boid *boids* *comfort-dist*)))
>       (unless (null all-nears)
>     (let ((num-enemy-boids (length (boids-of-type
>                     all-nears
>                     (enemy-type
>                      (class-name (class-of boid))))))
>           (num-friendly-boids (length (boids-of-type
>                        all-nears
>                        (class-name (class-of boid))))))
>       (when (> num-enemy-boids num-friendly-boids)
>         (print (class-name (class-of boid)))
>         (change-class boid (enemy-type boid))))))))
From: Robert St. Amant
Subject: Re: question about (class-name (class-of var))
Date: 
Message-ID: <lpn8yevigih.fsf@haeckel.csc.ncsu.edu>
charlieb <··@privacy.net> writes:

> Ok so I figured it out. I feel stupid now, but what's new.

Free coding style advice: Instead of using

  (eq (class-name (class-of <instance>)) <symbol>)

you might try

  (typep <instance> <symbol>)

Consider what happens if you ever need subclasses of your war-boids.

> charlieb wrote:
> 
> > Hi,
> >     I'm having a little problem with this function or rather the
> > flet part of it. The two print statements, which should be the same
> > return WAR-BOID-<COLOUR> and SYMBOL for the main body and the flet
> > respectively. Can you help me with this 'cause I can't figure it out.
> > Cheers
> > Charlieb
> > (defun boid-war (boid)
> >   "The idea is that if there are more enemy boids than friends
> > within the zone this boids should change sides."
> >   (flet ((enemy-type (b)
> >                (if (eq (print (class-name (class-of b)))
> >                    'war-boid-red)
> >                'war-boid-blue
> >              'war-boid-red)))
> >     (let ((all-nears (near-boids boid *boids* *comfort-dist*)))
> >       (unless (null all-nears)
> >     (let ((num-enemy-boids (length (boids-of-type
> >                     all-nears
> >                     (enemy-type
> >                      (class-name (class-of boid))))))
> >           (num-friendly-boids (length (boids-of-type
> >                        all-nears
> >                        (class-name (class-of boid))))))
> >       (when (> num-enemy-boids num-friendly-boids)
> >         (print (class-name (class-of boid)))
> >         (change-class boid (enemy-type boid))))))))

-- 
Rob St. Amant
http://www4.ncsu.edu/~stamant
From: charlieb
Subject: Re: question about (class-name (class-of var))
Date: 
Message-ID: <2it9olFqklusU1@uni-berlin.de>
Thanks, that was my first foray into the world of CLOS and since your 
giving out free advice I have a question :)

Is there are standard way of finding the superclass/es of an object?


Robert St. Amant wrote:
> charlieb <··@privacy.net> writes:
> 
> 
>>Ok so I figured it out. I feel stupid now, but what's new.
> 
> 
> Free coding style advice: Instead of using
> 
>   (eq (class-name (class-of <instance>)) <symbol>)
> 
> you might try
> 
>   (typep <instance> <symbol>)
> 
> Consider what happens if you ever need subclasses of your war-boids.
> 
> 
>>charlieb wrote:
>>
>>
>>>Hi,
>>>    I'm having a little problem with this function or rather the
>>>flet part of it. The two print statements, which should be the same
>>>return WAR-BOID-<COLOUR> and SYMBOL for the main body and the flet
>>>respectively. Can you help me with this 'cause I can't figure it out.
>>>Cheers
>>>Charlieb
>>>(defun boid-war (boid)
>>>  "The idea is that if there are more enemy boids than friends
>>>within the zone this boids should change sides."
>>>  (flet ((enemy-type (b)
>>>               (if (eq (print (class-name (class-of b)))
>>>                   'war-boid-red)
>>>               'war-boid-blue
>>>             'war-boid-red)))
>>>    (let ((all-nears (near-boids boid *boids* *comfort-dist*)))
>>>      (unless (null all-nears)
>>>    (let ((num-enemy-boids (length (boids-of-type
>>>                    all-nears
>>>                    (enemy-type
>>>                     (class-name (class-of boid))))))
>>>          (num-friendly-boids (length (boids-of-type
>>>                       all-nears
>>>                       (class-name (class-of boid))))))
>>>      (when (> num-enemy-boids num-friendly-boids)
>>>        (print (class-name (class-of boid)))
>>>        (change-class boid (enemy-type boid))))))))
> 
> 
From: Edi Weitz
Subject: Re: question about (class-name (class-of var))
Date: 
Message-ID: <87y8muzd7n.fsf@bird.agharta.de>
On Fri, 11 Jun 2004 09:45:09 +0100, charlieb <··@privacy.net> wrote:

> Is there are standard way of finding the superclass/es of an object?

Not in the ANSI standard, but the MOP[1] defines the generic function
CLASS-DIRECT-SUPERCLASSES. Most Lisps implement the MOP so you'll
probably have this available. Try APROPOS to check if you have this
function.

Edi.


[1] <http://www.alu.org/mop/index.html>
From: Rahul Jain
Subject: Re: question about (class-name (class-of var))
Date: 
Message-ID: <87y8msljkl.fsf@nyct.net>
Edi Weitz <···@agharta.de> writes:

> On Fri, 11 Jun 2004 09:45:09 +0100, charlieb <··@privacy.net> wrote:
>
>> Is there are standard way of finding the superclass/es of an object?
>
> Not in the ANSI standard, but the MOP[1] defines the generic function
> CLASS-DIRECT-SUPERCLASSES.

Also, CLASS-PRECEDENCE-LIST if you're looking for the full list of
indirect superclasses.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist