CLIPS无法识别解模板名称

问题描述

我正在尝试撤消deftemplate事实,但是当我执行此CLIPS时,总是说我必须先声明deffunction才是合适的deftemplate。这似乎是什么问题?

我已附上相关代码

我收到此错误

[EXPRNPSR3]农业缺少功能声明。

问题出在哪里?

(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))

解决方法

input规则的RHS中,您声明:

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

这被解释为“运行功能农业并将其结果绑定到?d”。

您可能想做的是:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...