RE: JESS: [EXTERNAL] Dynamic rule matching in the LHS
"Friedman-Hill, Ernest" <[email protected]> Tue, 30 Jul 2013 14:05:47 +0000
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <[email protected]> |
Not sure what "dynamic" means in this context. But you can use the "foral=
l" conditional element to implement this rule. You could read the LHS her=
e as "For all values of ?name in bag-of-items, there's a corresponding it=
em fact."
(defrule check-bag-valid
(forall
(bag-of-items (names $? ?name $?))
(item (name ?name)))
=3D>
(printout t "The bag is valid" crlf))
NOTE: Like many complex Jess rules, this one won't fire unless before add=
ing your facts you've executed the "(reset)" command to asset (initial-fa=
ct).
-----Original Message-----
From: [email protected] [mailto:[email protected]] On=
Behalf Of Aurelien Mazurie
Sent: Friday, July 26, 2013 4:56 PM
To: jess-users
Subject: JESS: [EXTERNAL] Dynamic rule matching in the LHS
Dear Jess users,
I am wondering how to write a rule that would dynamically match multiple =
facts based on their names.
Let say I have two types of facts; one representing the information that =
an item (with a given name) exists, and the other one representing a list=
of items (e.g., as a list of names in a multislot). It could be somethin=
g like
this:
(deftemplate item (slot name))
(deftemplate bag-of-items (multislot names))
(assert (item (name A))
(assert (bag-of-items (names A B))
What I am trying to write is a rule that would, for any bag-of-items fact=
, fire if all the items listed in the multislot 'name' are item facts tha=
t have been asserted.
I am wondering if there is an easy way to do that, or if I'll need to hac=
k my way through it with loops and tests in the LHS of my rule.
Any suggestion?
Best,
Aur=C3=A9lien
--
View this message in context: http://jess.2305737.n4.nabble.com/Dynamic-r=
ule-matching-in-the-LHS-tp4654176.html
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 yo=
ur own address!) List problems? Notify [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]=
.
--------------------------------------------------------------------