Well, what you want to do is really to have rules fire on system metadata rather than data -- i.e., you're not interested in the values of things, but rather when things happen. Obviously that's not what rules are designed to do, or this wouldn't be so hard. You could consider replacing these two rules with a JessEventListener(s) watching for DEFINSTANCE and FACT + MODIFIED events (for the latter, you'd just check the name for your object type.) That's what they're there for!
I think David Korz wrote: > No, this doesn't do what want. Rule-1 fires when MyObj is > definstance'd. This activates rule-2a which runs and asserts the > first-id fact. This activates rule-2b which fires immediately. In the > end all 3 rules have fired without MyObj getting modified. I don't want > rule-2b to fire until MyObj is modified. > > On Thursday, October 9, 2003, at 06:33 PM, [EMAIL PROTECTED] wrote: > > > If you can split rule-2 into two rules, you can say something like > > > > (defrule rule-2a > > (MyObj > > (id ?id) > > (OBJECT ?obj) > > ) > > (id ?id) > > (not (first-id ?id)) > > => > > (assert (first-id ?id)) > > ) > > > > (defrule rule-2b > > (MyObj > > (id ?id) > > (OBJECT ?obj) > > ) > > (exists (first-id ?id)) > > => > > (myfunction ?obj) > > ) > > > > I *think* this is equivalent to what you're trying to do. > > > > > > > > I think David Korz wrote: > >> I want to have a rule that fires for a definstance when it is created > >> and other rules from when it is subsequently updated. The update rules > >> should not fire when the definstance is created, only when it is > >> updated. I can get a rule to first just once for a definstance but the > >> only way I could get a rule to fire only on updates was to use a > >> defquery on the RHS. Is there a better way to do this? > >> > >> MyObj is the definstance for a bean with id as a property. > >> > >> ; Rule that runs once for a definstance. > >> ; Assert a fact so we never do it twice. > >> (defrule rule-1 > >> (MyObj > >> (id ?id) > >> (OBJECT ?obj) > >> ) > >> (not (id ?id)) > >> => > >> (assert (id ?id)) > >> (myfunction1 ?obj) > >> ) > >> > >> ; Rule for updates. > >> (defrule rule-2 > >> (MyObj > >> (id ?id) > >> (OBJECT ?obj) > >> ) > >> (id ?id) > >> => > >> (bind ?i (count-query-results find-first-id ?id)) > >> (if (> ?i 0) then > >> (myfunction2 ?obj) > >> else > >> (assert (first-id ?id)) > >> ) > >> ) > >> > >> (defquery find-first-id > >> "Look for first-id fact for id" > >> (declare (variables ?id)) > >> (first-id ?id) > >> ) > >> > >> -------------------------------------------------------------------- > >> 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] > >> -------------------------------------------------------------------- > >> > > > > > > > > --------------------------------------------------------- > > Ernest Friedman-Hill > > Distributed Systems Research Phone: (925) 294-2154 > > Sandia National Labs FAX: (925) 294-2234 > > PO Box 969, MS 9012 [EMAIL PROTECTED] > > Livermore, CA 94550 http://herzberg.ca.sandia.gov > > > > -------------------------------------------------------------------- > > 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] > > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > 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] > -------------------------------------------------------------------- > --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- 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] --------------------------------------------------------------------
