This is just my bias opinion, but the bigger issue is this. Rule
programming is logic programming. Therefore you need to think in those
terms.  What you need to do is check if the item is already in the box
before firing the rule. That can be done with either TESTCE.

The rule you have tells the rule engine to fire when ever there's an
item and box. The function is always modifying the box after it adds
the item to the multislot. the engine is doing exactly what you told
it to do. Instead, what you should do is "add the item to the box if
it isn't already in it"

hope that helps

peter

On Thu, May 21, 2009 at 9:14 PM, Aaron Novstrup
<anovst...@stottlerhenke.com> wrote:
> Hi Dr. Friedman-Hill,
>
> I ran into a bug in my rulebase today that I traced back to the use of the
> no-loop declaration (test case below).  This has bit other users in the past
> (see urls below), and I think it should be regarded as a bug.
> In my example, two separate facts (f-2 and f-3) activate a no-loop rule.
>  When the rule fires for f-3, it modifies (retracts and reasserts) another
> fact, causing the activation associated with f-2 to be removed.  However,
> when the fact is reasserted, 'no-loop' prevents the engine from restoring
> the activation for f-2.
>
> This behavior seems inconsistent with the definition of the no-loop
> declaration.  The RHS of a 'no-loop' rule must not *cause* the immediate
> reactivation of the same rule, but it should not inhibit an activation that
> was already present when the rule fired.
>
> Thanks,
> ~~Aaron Novstrup
>
> http://www.mail-archive.com/jess-users@sandia.gov/msg08025.html
> http://www.mail-archive.com/jess-users@sandia.gov/msg09870.html
>
> ; JESS test case
> (deftemplate box
>  (multislot items))
>
> (deffunction put-in-box (?box ?item)
>  (bind ?items (fact-slot-value ?box items))
>  (modify ?box (items (union$ ?items (create$ ?item))))
>  )
>
> (defrule box-packer-rule
>  (declare (no-loop TRUE))
>  (moving ?item)
>  ?b <- (box)
>  =>
>  (put-in-box ?b ?item)
>  )
>
> (watch all)
> (reset)
>
> (assert (box))
> (assert (moving elvis-bobble-head-collection))
> (assert (moving jimi-hendrix-autographed-guitar))
> (run)
>
> ; execution trace
> Jess, the Rule Engine for the Java Platform
> Copyright (C) 2008 Sandia Corporation
> Jess Version 7.1p2 11/5/2008
>
> ==> Focus MAIN
> ==> f-0 (MAIN::initial-fact)
> ==> f-1 (MAIN::box (items ))
> ==> f-2 (MAIN::moving elvis-bobble-head-collection)
> ==> Activation: MAIN::box-packer-rule :  f-2, f-1
> ==> f-3 (MAIN::moving jimi-hendrix-autographed-guitar)
> ==> Activation: MAIN::box-packer-rule :  f-3, f-1
> FIRE 1 MAIN::box-packer-rule f-3, f-1
> <== Activation: MAIN::box-packer-rule :  f-2, f-1
> <=> f-1 (MAIN::box (items jimi-hendrix-autographed-guitar))
> <== Focus MAIN
>
>


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users y...@address.com'
in the BODY of a message to majord...@sandia.gov, NOT to the list
(use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
--------------------------------------------------------------------

Reply via email to