String 剪辑使用字符串创建比较条件
我对Clips专家系统非常陌生 我正在寻找用于比较以前规则中的文本的语法 像这样String 剪辑使用字符串创建比较条件,string,syntax,compare,conditional-statements,clips,String,Syntax,Compare,Conditional Statements,Clips,我对Clips专家系统非常陌生 我正在寻找用于比较以前规则中的文本的语法 像这样 (defrule GetGender (declare (salience 100)) (printout t "What's your gender ? (Male/Female): ") (bind ?response (read)) (assert (Gender (gender ?response)))) 当我从上面得到答案,比如“男性”,我希望下面的规则是有效的 (defrule GetShirt (d
(defrule GetGender
(declare (salience 100))
(printout t "What's your gender ? (Male/Female): ")
(bind ?response (read))
(assert (Gender (gender ?response))))
当我从上面得到答案,比如“男性”,我希望下面的规则是有效的
(defrule GetShirt
(declare (salience 99))
(Gender (gender ?l))
(test (= ?l Male))
=>
(printout t "What's your shirt color ? (Blue/Black): ")
(bind ?response (read))
(assert (Shirt (shirt ?response))))
但是seem(test and=)不是字符串比较的语法,而且我的英语不够好,我甚至不知道代码中的“?l”是什么意思
有人能帮我解决这个问题吗
谢谢。
=
用于比较数字
对于字符串,您需要使用eq
函数
In [1]: (eq "foo" "bar")
FALSE
In [2]: (eq "foo" "foo")
TRUE
使用=比较数字,使用eq比较任何类型的值。在GetShirt规则中,标记?l是一个绑定到性别槽值的变量,以便可以在表达式(=?l Male)中使用。在对常量进行简单比较时,不必使用test条件元素。您只需在模式中使用常量:
CLIPS>
(deftemplate response
(slot attribute)
(slot value))
CLIPS>
(defrule GetGender
=>
(printout t "What's your gender ? (Male/Female): ")
(bind ?response (read))
(assert (response (attribute gender) (value ?response))))
CLIPS>
(defrule GetShirt
(response (attribute gender) (value Male))
=>
(printout t "What's your shirt color ? (Blue/Black): ")
(bind ?response (read))
(assert (response (attribute shirt) (value ?response))))
CLIPS> (reset)
CLIPS> (run)
What's your gender ? (Male/Female): Male
What's your shirt color ? (Blue/Black): Blue
CLIPS>
嗨,noxdafox谢谢你的回答,你能告诉我如何在我的代码中使用这个吗,我不太明白,“foo”和“bar”是什么吗?嗨,Gary Riley,非常感谢你的例子,我几分钟前已经和你一起做了@noxdafox帮助,我很感激。