Thanks, David, for your excellent reply. Everything you've said is
correct, but I wanted to add something. Rick, you're using an "if-
then" statement on the right-hand side of your rule, and that's often
a sign that the rule isn't conceived right. I imagine you want to
print "None found" only if no gym-stations satisfy your criteria, but
the way you've written things, you'll print "None found" for each gym-
station fact that doesn't contain an arms-upperfront element -- so
both "Found" and "Not found" could be printed on the same run!
Instead of using an if-then, you should instead be more specific
about your pattern matching; and furthermore, you should write a
separate rule for each possible outcome. So, for example, I might write
(defrule detect-arms-upperfront
(gym-station (ident ?any) (purpose $? arms-upperfront $?) )
=>
(printout t " Found arms-upperfront " ?any crlf ))
(defrule no-arms-upperfront
(not (gym-station (purpose $? arms-upperfront $?) ))
=>
(printout t " Not found " crlf ))
On Mar 14, 2007, at 8:39 AM, David Corsar wrote:
Rick
There area two errors in this code that are stopping it from
working: in the deffacts you are using station instead of gym-
station; and in the rule line (gym-station (ident ?any) (purpose ?
alist) ), the ?alist should be $?alist to indicate that it should
be treated as a multislot, which should then cause the member$
function to work correctly. I attach below the revised code that
seems to work fine.
David
(deftemplate gym-station (slot ident) (multislot purpose))
(deftemplate gym-station (slot ident) (multislot purpose))
(deffacts gym-station-data
(gym-station (ident s1) (purpose arms-upperfront back))
(gym-station (ident s2) (purpose legs abs))
(gym-station (ident s3) (purpose abs shoulders arms-upperfront)))
(defrule detect-arms-upperfront
(gym-station (ident ?any) (purpose $?alist) )
=>
(if (member$ arms-upperfront ?alist) then
(printout t " Found arms-upperfront " ?any crlf )
else
(printout t " None found " crlf)))
(reset)(run)
ricktee wrote:
Hi, I'm working on a school project using JESS 6.1 and using the
"JESS in
action" as my manual.
I got 3 "gym-machine" facts, each with 2 slots they are "ident" and
"purpose"
I'm trying to write a rule that checks all 3 facts's "purpose"
slot for the
existent of "arms-upperfront"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
(deftemplate gym-station (slot ident) (multislot purpose))
(deffacts gym-station-data
(station (ident s1) (purpose arms-upperfront back))
(station (ident s2) (purpose legs abs))
(station (ident s3) (purpose abs shoulders arms-upperfront)))
(defrule detect-arms-upperfront
(gym-station (ident ?any) (purpose ?alist) )
=>
(if (member$ arms-upperfront ?alist) then
(printout t " Found arms-upperfront " ?any )
else
(printout t " None found " )))
(reset)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;
I'm having trouble at the defrule (gym-station (ident ?any)
it seems I can't use ?any to represent all 3 facts. I'm trying to
get the
rule to cycle through all 3 facts. I have try to remove (ident ?
any) but it
still wont cycle through the 3 facts. Please help me, am I writing
it the
wrong way?
Thank you very much for your time
Rick
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
[EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify owner-jess-
[EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------