0
votes

I am trying to retract a deftemplate fact but when I do this CLIPS keeps saying I have to first declare the deffunction yet it is the appropriate deftemplate.What seems to be the problem?

I have attached the related code:

I get this error:

[EXPRNPSR3] Missing function declaration for Agriculture.

What seems to be the problem?

(deftemplate Agriculture
  (slot weed
        (type SYMBOL)
        (allowed-symbols B G))

  (slot crop
        (type SYMBOL)
        (allowed-symbols C S))

  (slot organic-matter
        (type INTEGER)
        (allowed-values 1 2 3)))

(defrule Sencor-1
  (and (Agriculture(weed B))
       (Agriculture(crop C|S))
       (Agriculture(organic-matter 1)))
 =>
  (printout t "Do not use Sencor!!"crlf))

(defrule Sencor-2
  (and (Agriculture(weed B))
       (Agriculture(crop C|S))
       (Agriculture(organic-matter 2|3)))
 =>
  (printout t " " crlf "Use 3/4  pt/ac of Sencor" crlf ))

(defrule Lasso-1
  (and (Agriculture(weed B|G))
       (Agriculture(crop C|S))
       (Agriculture(organic-matter 1)))
 =>
  (printout t crlf"Use 2 pt/ac of Lasso" crlf))

(defrule Lasso-2
  (and (Agriculture(weed B|G))
       (Agriculture(crop C|S))
       (Agriculture(organic-matter 2)))
 =>
  (printout t crlf "Use 1 pt/ac of Lasso" crlf))

(defrule Lasso-3
  (and (Agriculture(weed B|G))
       (Agriculture(crop C|S))
       (Agriculture(organic-matter 3)))
 =>
  (printout t crlf "Use 0.5 pt/ac of Lasso" crlf))

(defrule Bicep-1
  (and (Agriculture(weed B|G))
       (Agriculture(crop C))
       (Agriculture(organic-matter 1)))
 =>
  (printout t crlf "Use 1.5 pt/ac of Bicep" crlf))

(defrule Bicep-2
  (and (Agriculture(weed B|G))
       (Agriculture(crop C))
       (Agriculture(organic-matter 2)))
 =>
  (printout t crlf"Use 2.5 pt/ac of Bicep" crlf))

(defrule Bicep-3
  (and (Agriculture(weed B|G))
       (Agriculture(crop C))
       (Agriculture(organic-matter 3)))
 =>
  (printout t crlf "Use 3 pt/ac of Bicep" crlf))

(defrule input
  (initial-fact)
 =>
  (printout t crlf "What is the crop? (C:corn,S:soybean)")
  (bind ?a (read))
  (assert(Agriculture(crop ?a))) ;gets input from user
  (printout t crlf "What is the weed problem? (B:broadleaf, G:grass)")
  (bind ?b (read))
  (assert(Agriculture(weed  ?b)))
  (printout t crlf "What is the % of organic matter content? (1:<2%,2:2-4%,3:>4%)")
  (bind ?c (read))
  (assert(Agriculture(organic-matter ?c)))
  ?d <- (Agriculture(crop ?a) (weed ?b)  (organic-matter ?c))
  (printout t  ""crlf crlf "RECOMMENDATIONS:"crlf)
  (retract ?d))
1

1 Answers

0
votes

In the RHS of the input rule you state:

?d <- (Agriculture(crop ?a) (weed ?b)  (organic-matter ?c))

This is interpreted as "Run function Agriculture and bind its results into ?d".

What you probably are trying to do is:

(bind ?d (assert (Agriculture (crop ?a) (weed ?b)  (organic-matter ?c))))