The following code in the Jess Tab continuously inserts the same instance into a multivalued slot.
(defrule satisfactibleEstudio
(object (is-a Estudio)
(OBJECT ?user)
(nombre ?name)
(preferencias_minimas ?pref))
(object (is-a Chalet)
(OBJECT ?viv)
(precio ?p&: (and
(>= ?p (slot-get ?pref precio_minimo))
(<= ?p (slot-get ?pref precio_maximo))))
(tamanno ?t&: (and
(>= ?t (slot-get ?pref tamanno_minimo))
(<= ?t (slot-get ?pref tamanno_maximo))))
(componentes $?comp&: (>= (get-dorms $?comp) (slot-get ?pref dormitorios))))
=>
(slot-insert$ ?user satisfactibles 1 ?viv))
However, if I replace the slot-insert$ function by a printout it works as intended. What am I doing wrong?
Update: So apparently it's continuously inserting the same instance into the slot, however with a printout it only prints once per match.
See the Jess manual about modifying a fact on the right hand side:
If a rule includes the declaration (declare (no-loop TRUE))
, then nothing that a rule does while firing can cause the immediate reactivation of the same rule; i.e., if a no-loop rule matches a fact, and the rule modifies that same fact such that the fact still matches, the rule will not be put back on the agenda, avoiding an infinite loop.