我有该代码:
(deftemplate country
(slot name)
(multislot flag_colors))
(deffacts countries
(country (name "United States of America") (flag_colors red white blue))
(country (name "Belgium") (flag_colors black yellow red))
(country (name "Poland") (flag_colors white red))
(country (name "Monaco") (flag_colors white red))
(country (name "Sweden") (flag_colors yellow blue))
(country (name "Panama") (flag_colors red white blue))
(country (name "Jamaica") (flag_colors black yellow green))
(country (name "Colombia") (flag_colors yellow blue red))
(country (name "Italy") (flag_colors green white red))
(country (name "Ireland") (flag_colors green white orange))
(country (name "Greece") (flag_colors blue white))
(country (name "Botswana") (flag_colors blue white black)))
(defrule find-countries-with-colors
?c <- (country (name ?name) (flag_colors $?colors))
?input-colors <- (input-colors $?userColors)
(test (subsetp $?userColors $?colors))
=>
(printout t "Country: " ?name crlf))
(deffunction subsetp (?sublist ?list)
(if (or (not (listp ?sublist)) (not (listp ?list)))
then FALSE
else
(foreach ?element ?sublist
(if (not (member ?element ?list))
then return FALSE))
return TRUE))
(defrule get-user-input
(declare (salience 10))
=>
(printout t "Enter colors separated by spaces: ")
(bind ?colors-string (readline))
(bind ?colors (explode$ ?colors-string))
(assert (input-colors (create$ ?colors))))
(defrule no-match-found
(not (find-countries-with-colors))
=>
(printout t "No country found with the specified colors." crlf))
(defrule run
(declare (salience -10))
=>
(run))
当我运行它时,出现以下错误:
定义 deftemplate:国家 定义 deffacts:国家 定义 defrule:find-country-by-colors [PRNTUTIL2] 语法错误:检查 defrule 的适当语法。
错误:(defrule MAIN::find-country-by-colors?request <-(request(定义 deffunction:subsetp [DFFNXPSR2] 不允许 Deffunctions 替换外部函数。
错误:(deffunction MAIN::subsetp(定义 deffunction:main
[EXPRNPSR3] 缺少颜色函数声明。
错误:(deffunction MAIN::main()(printout t“输入以空格分隔的颜色:”)(bind?user-colors(explode$(readline)))(assert(request(colors FALSE
请帮帮我,我不知道。我只是在学习。
该程序的本质是,它应该要求输入颜色,然后根据输入的颜色输出所有国旗包含所有这些颜色的国家。
这是您的代码中的错误:
您收到此错误是因为您尝试重新定义已存在的函数: