You're the victim of an optimization.
A brief explanation: when a (modify) function is compiled, Jess can't tell what kind of fact is going to be bound to the first argument. Therefore, when the (modify) is later first executed, Jess has to actually look up the slot name in a table to find the proper offset at which to store the new slot data. This lookup is slow (not terribly slow, but nontrivial). The (modify) function call therefore saves this offset, so that the next time it is called, it can use the offset directly, which is noticeably faster. This obviously breaks horribly if, as you've established below, a single (modify) can be called on different types of facts which just coincidentally share a slot name. It never would have occurred to me to do this, and noone's ever complained before, so I think it's a very original notion on your part. I'll have to think about it before I decide whether this is a bug that needs to be addressed, something that needs to be mentioned in the manual, or what. But you can fix your immediate problem simply by rearranging your deftemplates such that the "button" slot is at the same offset in each one -- i.e., make it the third slot in the "exit" template as well as in the "room" template. I think [EMAIL PROTECTED] wrote: > Hello, > > I have two templates: > (deftemplate room > (slot name) > (multislot exits) > (slot button)) > > (deftemplate exit > (slot name) > (multislot rooms) > (slot x (default 0)) > (slot y (default 0)) > (slot heading) ;into corridor (from first to last) > (slot open (default YES)) > (slot found (default NO)) > (slot button) > (slot id(default 0))) > > I read in a fact file of rooms and exits, and I then generate a map of > buttons for each. I try to store the button external reference in the > "button" slot, and I think I am successful, but there is an unexpected side > effect. Just before the suspected modify statement, if I printout the x and > y values, the are all zero as they should be. However, when I check (at > ;here) the x values have become external references to buttons. Why? > Here's the rule: > (defrule create-mapPanel (declare (salience 20)) > (mode initialize) > (map (nodes $?nodes)(width ?w)(height ?h)) > ?fact <- (create-map) > => > (bind ?*mapPanel* (new Panel)) > (set ?*mapPanel* layout (new GridLayout ?h ?w)) > (foreach ?node $?nodes > (if (or (eq "R" (sub-string 1 1 ?node)) (eq "H" (sub-string 1 1 ?node)) > (eq "N" (sub-string 1 1 ?node))) > then (bind ?e (run-query get-room-fact ?node)) > else (bind ?e (run-query get-exit-fact ?node))) > (while (?e hasNext) > (bind ?token (call ?e next)) > (bind ?factid (call ?token fact 1))) > (modify ?factid (button (bind ?*b* (new Button ?node)))) > ;modify that causes unexpected change > (if (eq "D" (sub-string 1 1 ?node)) ;here > then (printout t ?node "-") ;here > (printout t " x=" (call ?factid getSlotValue "x")) > ;here > (printout t " y=" (call ?factid getSlotValue "y") crlf)) > ;here > (if (eq NULL ?node) > then (?*b* hide) > else (?*b* addActionListener (new ActionListener > room-prompt-button-handler (engine))) > (?*b* setBackground (get-member java.awt.Color white))) > (?*mapPanel* add ?*b*)) > (retract ?fact) > (assert (need-gui))) > > > > --------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' > in the BODY of a message to [EMAIL PROTECTED], NOT to the > list (use your own address!) List problems? Notify [EMAIL PROTECTED] > --------------------------------------------------------------------- > --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 Org. 8920, MS 9012 [EMAIL PROTECTED] PO Box 969 http://herzberg.ca.sandia.gov Livermore, CA 94550 --------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] ---------------------------------------------------------------------
