Question

This is for a homework assignment, but I am having a really hard time finding good jess information on the web. I'm trying to use a multislot to to solve a problem, but I can't find anything on how to match the different values. I have this:

(deftemplate patient (slot name)(multislot symptoms))

(deffacts init 
(patient (name john) (symptoms very-high-fever cough)))

How can I match the left hand side for just a very-high-fever? This works if I know that the very-high-fever is the first symptom, but I can't be sure of that, so I need to be able to match if a very-high-fever is either symptom.

(defrule high-fever
(patient (name ?n)(symptoms very-high-fever ?))
=>
(printout t ?n " has a high fever." crlf))

I've tried various combinations of field constraints, but I can't seem to get it right and nothing online is giving me any clues.

Thanks.

Was it helpful?

Solution

Use a blank multifield before and after the item you want to match; they match zero or more items. So, something like

(patient (name ?n) (symptoms $? very-high-fever $?))

Will match any patient with the very-high-fever symptom in any position.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top