Thank you very much!

I was gonna use the "add to multislot" method for my other fact, not for the
gym-machine facts : )

Thanks a bunch. Thank goodness for you guys, 'cos my Uni don't teach JESS,
and there isn't much examples online compare to Java.

My Uni only teach Java + a bit prolog + a bit of sml, so I'm hoping to get a
few extra credit for doing the project in JESS.

Thanks again!


David Corsar wrote:
> 
> Rick
> 
> One way of doing this is to use the modify function (see 
> http://herzberg.ca.sandia.gov/jess/docs/70/functions.html#modify) along 
> with the create$ function 
> (http://herzberg.ca.sandia.gov/jess/docs/70/functions.html#create$) 
> similar to the following
> 
> g <- (gym-station (ident ?any) (purpose $?alist) )
> (modify ?g (purpose (create$ ?alist lower-legs)))
> 
> The following rule adds lower-legs to the purpose of any gym-station 
> that has arms-upperfront in its purpose.
> 
> (defrule detect-arms-upperfront
>    ?g <- (gym-station (ident ?any) (purpose $?alist) )
>    (test (member$ arms-upperfront ?alist))
>    (test (not (member$ lower-legs ?alist)))
>    =>
>    (modify ?g (purpose (create$ ?alist lower-legs)))
>    (printout t " Found arms-upperfront " ?any crlf ))
> 
> Note the test to check that lower-legs isn't already there, if the test 
> is not there the rule will run forever; maybe Ernest can provide a way 
> to change the value without having the resulting modified fact retrigger 
> the rule.
> 
> David
> 
> ricktee wrote:
>> Thanks a bunch David & Ernest! That clears up alot!
>>
>> It's taking me forever to understand this rule-based style. Like in the
>> "JESS in action" book, the example inside the file "taxes.clp" the "ask
>> module" part, that part is pretty crazy.
>>
>> Just one more thing please, how do I add another object into a
>> "multislot"?
>> After it is created.
>>
>> Like in the fact
>> (assert (gym-station (ident s1) (purpose arms-upperfront back)))
>>
>> How can I add "lower-legs" into the "purpose multislot" so that it
>> becomes.
>> (gym-station (ident s1) (purpose arms-upperfront back lower-legs))
>>
>> I have tried the docs, the book, and goggle it, looking for terms like
>> "add"
>> "multislot" "list" but I can't find any.
>>
>> Thanks again
>> Rick
>>
>>
>> Ernest Friedman-Hill wrote:
>>   
>>> 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]
>>> --------------------------------------------------------------------
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 
> -- 
> 
> David Corsar
> Department of Computing Science
> Meston Building
> University of Aberdeen
> Aberdeen
> AB24 3UE
> Scotland
> UK
> Phone +44 (0)1224 274485
> http://www.csd.abdn.ac.uk/~dcorsar
> [EMAIL PROTECTED]
> 
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Compare-the-2nd-slot-of-all-facts-tf3401443.html#a9488226
Sent from the Jess mailing list archive at Nabble.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]
--------------------------------------------------------------------

Reply via email to