预期参数 #1 在 CLIPS 代码中是整数或浮点数

Expected argument #1 to be of type integer or float on CLIPS code

我的代码有一个问题,即在给定的田间情况下推荐除草剂和施用率。

(deftemplate plant
  (multislot weed)
  (multislot crop))

(deftemplate Herbicide
  (slot orgmatter)
  (slot sencor)
  (slot lasso)
  (slot bicep))

(deffacts p
  (plant  (weed B) (crop C S))
  (plant  (weed B G) (crop C S))
  (plant  (weed B G) (crop C)))

(deffacts H
  (Herbicide  (orgmatter 1) (sencor 0.0) (lasso 2.0) (bicep 1.5))
  (Herbicide  (orgmatter 2) (sencor 0.75) (lasso 1.0) (bicep 2.5))
  (Herbicide  (orgmatter 3) (sencor 0.75) (lasso 0.5) (bicep 3.0)))

(defrule read-input
  =>
  (printout t "what is type of crop? (C:Corn , S:Soyabeans): ")
  (assert (crop(read)))
  (printout t "what is type of weed? (B:broadleaf , G:gress): ")
  (assert (weed(read)))
  (printout t "what is the organic matter? (1:<2% ,2: 2-4%, 3: >4%: ")
  (assert (orgmatter(read))))

(defrule check-input
  (crop ?crop)
  (weed ?weed)
  (orgmatter ? orgmatter)
  (plant (weed $?weed1) (crop $?crop1))
  (Herbicide  (orgmatter ?orgmatter1) (sencor ?sencor1) (lasso ?lasso1)(bicep ?bicep1))
  (test (member$ ?crop ?crop1))
  (test (member$ ?weed ?weed1))
  (test (= orgmatter ?orgmatter1))
  =>
  (printout t "you can use" ?sencor1 " pt/ac of sencor" crlf)
  (printout t "you can use" ?lasso1 " pt/ac of lasso" crlf)
  (printout t "you can use" ?bicep1 " pt/ac of bicep" crlf)))

错误如下: Function = expected argument#1 to be of type integer or float

您的代码末尾有一个额外的 )

check-input中,你有一个测试:

(test (= orgmatter ?orgmatter1))

比较符号 orgmatter 和变量 ?orgmatter1= 测试仅适用于数字。如果要比较 SYMBOL 或 STRING,则需要使用 eq 函数。

(test (eq orgmatter ?orgmatter1))

不过,如果您没有在其他任何地方使用 ?orgmatter1,则进行文字匹配比测试更有效。

(Herbicide (orgmatter orgmatter) 
           (sencor ?sencor1) 
           (lasso ?lasso1) 
           (bicep ?bicep1))