Hi Duane,
Well, of course, an O-O stickler would tell you that this kind of
"downcasting" is to be avoided, and in most cases, it can be: if you
want to write a rule dealing with MAMMAL, you match on MAMMAL, not
ANIMAL (this will of course be more efficient, too.) Rules which treat
animals generically should match on ANIMAL; rules which know about
specific animal subtypes should match on the subtypes (MAMMAL).
Anyway, in the current system, for deftemplates (as opposed to
defclasses) I haven't put in a way to the the downcasting. You could
use the fact-slot-value function I've posted here before, which will
throw an exception if there's no such slot (remember you can catch
exceptions from Jess scripts).
For defclasses, you can get the OBJECT slot and try to call getters
deirctly on that.
I think Duane Morin wrote:
>
> Hi,
>
> I'm just now experimenting with the power of having one fact type extend
> another. Question : If I have a rule that fires on a common parent, how
> do I then decide what the actual type of the fact is so that I can work
> on it?
>
> For example:
>
> (deftemplate ANIMAL (slot name))
> (deftemplate MAMMAL extends ANIMAL (slot number-legs))
>
> ...
> (assert (MAMMAL (name CAT) (number-legs 4)))
> ...
>
> (defrule findAnimals
> (ANIMAL (name ?x))
> ...how do I now check if this thing is a MAMMAL, so that I can then check
> it's number-legs? Do I have to say:
> (MAMMAL (name ?x)(number-legs ?y))
>
> ???
>
>
> Thanks. It's a lousy example, I know, but it's the best I could think of
> without writing a minor treatise on what I want to do :)
>
> Duane
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list. List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------