Thanks, that's exactly the clarification I needed.
--
Richard Kasperowski
Tel: 617-576-1552, Fax: 617-576-2441
mailto:[EMAIL PROTECTED]
http://www.altisimo.com/
First, note the following two general rules:
1) Don't use "test" if you don't need to, and
2) direct matching is more efficient than function calls.
Therefore, I'd recomment rewriting your rule above as:
(defrule find-different-years
(automobile (model ?model) (year ?year-1))
(automobile (model ?model) (year ?year-2&~?year-1))
Note that using "?model" to match both facts means that both facts
must contain the same slot value. This rule says exactly the same
thing as the original, but does a lot less work during pattern
matching.
Now, as written, the rule matches any time the two years are
different, which means that any pair will match twice: 1,2 and 2,1 are
both valid matches. To remove the duplicates, just pick one specific
ordering. Since "year" is numeric, this is easy here:
(defrule find-different-years
(automobile (model ?model) (year ?year-1))
(automobile (model ?model) (year ?year-2&:(> ?year-1 ?year-2)))
i.e., the rule matches only one of the two possible orderings, when
?year-1 comes after ?year-2.
---------------------------------------------------------
Ernest Friedman-Hill
--------------------------------------------------------------------
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]
--------------------------------------------------------------------
- JESS: How to match slot values in LHS? Richard Kasperowski
- Re: JESS: How to match slot values in LHS? ejfried
- Richard Kasperowski
