Re: how to change clos slots

"Johan Lindberg" <[email protected]> Fri, 14 Mar 2008 17:46:15 +0100
Newsgroups gmane.lisp.lisa.general
Message-ID <[email protected]>
Hi again Pedro,

 >  but what I want to do is to change the slots of each instance. I tried
 >  the following code but I get a infinite loop:
 >
 >  (defrule rule-1 ()
 >   (?sonority (sonority (notes ?notes)))
 >   =>
 >   (modify ?sonority (tertian-p t)))

 The reason for the infinite loop is because LISA handles refraction
 and modifications just like CLIPS.

 While it won't place an Activation (a Rule + a set of Facts) on the
 Agenda if it has been executed before (aka Refraction). The problem is
 that the modify statement changes the Fact-index (of the ?sonority
 fact) and that also means that LISA will treat it as a "new" Fact. It
 won't show up on the list of previous Activations so Refraction won't
 work.

 Some engines (Jess) handle this type of situation a little better.
 Jess won't assign a new Fact-index unless the modify statement
 actually modifies a slot-value. It makes it easier to avoid this
 problem or it encourages you to write sloppy code, depends on how you
 look at it ;-)

 The easiest way to solve your problem is to modify the LHS so that it
 also matches (tertian-p nil). Try:

 (defrule rule-1 ()
  (?sonority (sonority (notes ?notes) (tertian-p nil)))

  =>
  (modify ?sonority (tertian-p t)))

 In general (using CLIPS, and LISA) you should include a match against
 the slot your modifying to make sure that it's not already been
 processed to avoid this sort of trouble.

 HTH
 Johan Lindberg
 [email protected]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/