0
votes

i have deftemplate for url that contains url itself and integer counter :

(deftemplate url_t
(slot counter
(type INTEGER)
(default 0))
(slot url
(type STRING)
(default "")))

and i am trying to define the rule to print url string if counter value >0

(defrule print-url
    (url_t (counter ?counter) (url ?url))
    (test (> ?counter 0))
=>
(printout t "url is " ?url crlf)
)

But when i try to change the values of url_t: (assert url_t (counter 2) (url "hello hello")) The rule is not executed. Where's my error?

1

1 Answers

1
votes

If the assert statement in your description is exactly what you entered, then that's your problem because the syntax is invalid. Other than that, there's nothing wrong with the syntax of your deftemplate or defrule:

CLIPS> (clear)
CLIPS> (unwatch all)
CLIPS> 
(deftemplate url_t
   (slot counter
      (type INTEGER)
      (default 0))
   (slot url
      (type STRING)
      (default "")))
CLIPS> 
(defrule print-url
   (url_t (counter ?counter) (url ?url))
   (test (> ?counter 0))
   =>
   (printout t "url is " ?url crlf))
CLIPS> (assert (url_t (counter 2) (url "hello hello")))
<Fact-1>
CLIPS> (facts)
f-0     (initial-fact)
f-1     (url_t (counter 2) (url "hello hello"))
For a total of 2 facts.
CLIPS> (agenda)
0      print-url: f-1
For a total of 1 activation.
CLIPS> (run)
url is hello hello
CLIPS> (modify 1 (counter 3) (url "goodbye goodbye"))
<Fact-2>
CLIPS> (agenda)
0      print-url: f-2
For a total of 1 activation.
CLIPS> (run 1)
url is goodbye goodbye
CLIPS> (modify 2 (counter 0) (url "won't fire"))
<Fact-3>
CLIPS> (agenda)
CLIPS>