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

Reply via email to