Hi,

Here's a function you could call from a rule RHS as 

(undefine-rules-which-start-with-prefix main)

(deffunction undefine-rules-which-start-with-prefix (?prefix)
  (bind ?list (call (engine) listDefrules))
  (while (call ?list hasMoreElements)
    (bind ?name (get (call ?list nextElement) name))
    (if (eq  (sub-string 1 (str-length ?prefix) ?name) (str-cat  ?prefix)) then
      (undefrule ?name))))

There are lots of problems with the code below: extra
parentheses (in the third "bind" and in the "neq"), the tacit
belief thet ?rule will contain the name of the rule, when in fact it
contains a jess.Defrule object as an EXTERNAL_ADDRESS; and a missing
"then" in the if-then statement.


I think M Ward wrote:
> 
> Hello everyone, 
> 
> I am searching for a way of erasing specifed defrules from the engine
> when the user has decided not to continue : (Essentially, I wish to
> leave only those defrules whose names commence with the phrase
> 'main').
> 
> As I am unfamiliar with the workings of Jess' Java reflection
> capabilities, I have scavanged some code previously sent to the Jess
> Users mailing list (the purpose of which was to save all defrules to a
> specified file) and come up with the following.  
> 
> (defrule main_clean-up
> "Erasing unwanted rules"
> ?fact1 <- (continue no)
> =>
>  (retract ?fact1)
>  (bind ?list (call (engine) listDefrules))
>  (while (call ?list hasMoreElements)
>    (bind ?rule (call ?list nextElement))   
>    (bind (?name (sub-string 1 4 ?rule)))
>    (if (neq (?name main)) 
>      (undefrule  ?rule))))    
> 
> Unfortunately this does not seem to work correctly.
> 
> Could someone please explain why this is the case and how the code
> could be rectified.
> 
> Many thanks,
> 
> Michael D.M. Ward
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------

Reply via email to