I have encountered some odd behavior using the slot-specific template declaration and multifields.

Consider the following code:

 

(reset)

(watch all)

 

(deftemplate MyClass

;   (declare (slot-specific TRUE))

   (multislot slot1)

   (multislot slot2))

 

(defrule rule1

    ?myClass <- (MyClass

        (slot2 $?slot2List&:(not (member$ "abc" ?slot2List))))

    =>

    (modify ?myClass

        (slot2 ?slot2List "abc"))

    (printout t "*** Rule 1 - slot 2 list " ?slot2List crlf))

 

(defrule rule2

    ?myClass <- (MyClass

        (slot1 $?slot1List)

        (slot2 $?slot2List&:(> (length$ ?slot2List) 1)))

;        (slot2 $?slot2List))

    =>

    (printout t "*** Rule 2 - slot 2 list: " ?slot2List " Length: " (length$ ?slot2List) crlf)

    (printout t "Fact slot value s1: " (fact-slot-value ?myClass slot1) crlf)

    (printout t "Fact slot value s2: " (fact-slot-value ?myClass slot2) crlf))

 

(assert

    (MyClass

        (slot1 "slot1Value")

        (slot2 "slot2Value")))

 

(run)

 

Running the code without the template declared as slot-specific I get the expected results

with rule1 firing first and then rule2:

 

MAIN::rule1: +1+1+1+1+t

MAIN::rule2: =1+1+1+1+1+t

 ==> f-1 (MAIN::MyClass (slot1 "slot1Value") (slot2 "slot2Value"))

==> Activation: MAIN::rule1 :  f-1

FIRE 1 MAIN::rule1 f-1

 <=> f-1 (MAIN::MyClass (slot1 "slot1Value") (slot2 "slot2Value" "abc"))

==> Activation: MAIN::rule2 :  f-1

*** Rule 1 - slot 2 list ("slot2Value")

FIRE 2 MAIN::rule2 f-1

*** Rule 2 - slot 2 list: ("slot2Value" "abc") Length: 2

Fact slot value s1: ("slot1Value")

Fact slot value s2: ("slot2Value" "abc")

 <== Focus MAIN

 

If I now declare the MyClass template as slot-specific, rule2 no longer fires:

 

MAIN::rule1: +1+1+1+1+t

MAIN::rule2: =1+1+1+1+1+t

 ==> f-1 (MAIN::MyClass (slot1 "slot1Value") (slot2 "slot2Value"))

==> Activation: MAIN::rule1 :  f-1

FIRE 1 MAIN::rule1 f-1

 <=> f-1 (MAIN::MyClass (slot1 "slot1Value") (slot2 "slot2Value" "abc"))

*** Rule 1 - slot 2 list ("slot2Value")

 <== Focus MAIN

 

Removing the (> length$ 1) constraint from rule 2 allows that rule to fire and in this case since rule1 happens

to fire first adding “abc” to the contents of slot2. Looking at the actual contents (fact-slot-value) of

slot2 when rule2 fires though, you can see both the values there () however the length of the multifield

still appears as 1 and only one value shows up if you printout the multifield variable:

 

MAIN::rule1: +1+1+1+1+t

MAIN::rule2: =1+1+1+1+t

 ==> f-1 (MAIN::MyClass (slot1 "slot1Value") (slot2 "slot2Value"))

==> Activation: MAIN::rule1 :  f-1

==> Activation: MAIN::rule2 :  f-1

FIRE 1 MAIN::rule1 f-1

 <=> f-1 (MAIN::MyClass (slot1 "slot1Value") (slot2 "slot2Value" "abc"))

*** Rule 1 - slot 2 list ("slot2Value")

FIRE 2 MAIN::rule2 f-1

*** Rule 2 - slot 2 list: ("slot2Value") Length: 1

Fact slot value s1: ("slot1Value")

Fact slot value s2: ("slot2Value" "abc")

 <== Focus MAIN

 

It would appear that the number of values in a multislot is not correctly represented

when the template is declared slot-specific.

 

Thanks,

 

- Howard

Reply via email to