Argh, sorry, I used "no-loop" in my example, but I meant "slot- specific."

On Jun 12, 2011, at 11:12 PM, Ernest Friedman-Hill wrote:

Oooh, that's a bad example; I'll have to fix the manual. If you type (watch all) before your code, you'll see that the rule actually fires twice; once when B is nil, and once when it's 3. But the second time it fires, the "modify" has no effect, since the slot is being modified to contain the value it already contains. Try this rule instead, both with and without no-loop (and use (watch all) so you can see what's going on:)

(defrule R (declare (no-loop TRUE))
 ?d <- (D (A 1))
 =>
 (modify ?d (B (+ ?d.B 1))))

Note that your initial assert needs to have a number in the B slot, or you'll get an error.



On Jun 12, 2011, at 8:08 PM, Felix Chan wrote:

Hi,

I have been trying to understand the slot-specific functionality which
is described in the JESS manual as follows:

---------------------------------------------------
6.18. The 'slot-specific' declaration for deftemplates
Deftemplate definitions can now include a "declare" section just as
defrules can. There are several different properties that can be
declared. One is "slot-specific". A template with this declaration
will be matched in a special way: if a fact, created from such a
template, which matches the left-hand-side of a rule is modified, the
result depends on whether the modified slot is named in the pattern
used to match the fact. As an example, consider the following:

Jess> (deftemplate D (declare (slot-specific TRUE)) (slot A) (slot B))
Jess> (defrule R
?d <- (D (A 1))
=>
(modify ?d (B 3)))
Without the "slot-specific" declaration, this rule would enter an
endless loop, because it modifies a fact matched on the LHS in such a
way that the modified fact will still match. With the declaration, it
can simply fire once. This behavior is actually what many new users
expect as the default; the technical term for it is refraction.
--------------------------------------------------

I tried the following without the slot-specific declaration, expecting
an infinite loop to occur:

(reset)
(deftemplate D (slot A) (slot B))

(defrule R
?d <- (D (A 1))
=>
(modify ?d (B 3)))

(bind ?f (assert (D (A 1))))
(facts)
(run)
(facts)

But I got the following outcome with no infinite loop:
f-0   (MAIN::initial-fact)
f-1   (MAIN::D (A 1) (B nil))
For a total of 2 facts in module MAIN.
f-0   (MAIN::initial-fact)
f-1   (MAIN::D (A 1) (B 3))
For a total of 2 facts in module MAIN.

It seems slot-specific makes no difference in the outcome. I suspect I
am missing a key concept here. Could someone explain?

Thanks.

Felix


--------------------------------------------------------------------
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 .
--------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
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 .
--------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
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