如何在 defrule 函数中传递参数?剪辑
How to pass a parameter in defrule function? CLIPS
我是 CLIPS 的新手,感谢您的帮助。
问题:
如果我有以下模板:
(deftemplate user
(slot id (type INTEGER))
(slot firstname (type STRING))
(slot lastname (type STRING))
(slot username (type STRING))
(slot average (type FLOAT))
)
我会从事实中获取用户名值,并检查是否有两个用户名相同但平均值不同的事实。例如,如果我们有:
(assert user (id 1) (firstname 'Mike') (lastname 'Mikeson') (username 'mike') (average 70.00))
(assert user (id 1) (firstname 'Mike') (lastname 'Mikeson') (username 'mike') (average 10.00))
(assert user (id 2) (firstname 'John') (lastname 'Johnson') (username 'john') (average 90.00))
我会计算具有相同用户名的事实,因此 'mike',并检查第一个事实是否在平均字段中与第二个事实具有相同的值。
我尝试在网上搜索,但关于 CLIPS 的信息很少
CLIPS (6.4 2/9/21)
CLIPS>
(deftemplate user
(slot id (type INTEGER))
(slot firstname (type STRING))
(slot lastname (type STRING))
(slot username (type STRING))
(slot average (type FLOAT)))
CLIPS>
(deffacts users
(user (id 1) (firstname "Mike") (lastname "Mikeson") (username "mike") (average 70.00))
(user (id 1) (firstname "Mike") (lastname "Mikeson") (username "mike") (average 10.00))
(user (id 2) (firstname "John") (lastname "Johnson") (username "john") (average 90.00)))
CLIPS>
(defrule different-averages
(user (username ?un) (average ?avg1))
(user (username ?un) (average ?avg2&:(> ?avg2 ?avg1)))
=>
(println "User " ?un " has averages " ?avg1 " and " ?avg2 "."))
CLIPS> (reset)
CLIPS> (run)
User mike has averages 10.0 and 70.0.
CLIPS>
我是 CLIPS 的新手,感谢您的帮助。 问题: 如果我有以下模板:
(deftemplate user
(slot id (type INTEGER))
(slot firstname (type STRING))
(slot lastname (type STRING))
(slot username (type STRING))
(slot average (type FLOAT))
)
我会从事实中获取用户名值,并检查是否有两个用户名相同但平均值不同的事实。例如,如果我们有:
(assert user (id 1) (firstname 'Mike') (lastname 'Mikeson') (username 'mike') (average 70.00))
(assert user (id 1) (firstname 'Mike') (lastname 'Mikeson') (username 'mike') (average 10.00))
(assert user (id 2) (firstname 'John') (lastname 'Johnson') (username 'john') (average 90.00))
我会计算具有相同用户名的事实,因此 'mike',并检查第一个事实是否在平均字段中与第二个事实具有相同的值。
我尝试在网上搜索,但关于 CLIPS 的信息很少
CLIPS (6.4 2/9/21)
CLIPS>
(deftemplate user
(slot id (type INTEGER))
(slot firstname (type STRING))
(slot lastname (type STRING))
(slot username (type STRING))
(slot average (type FLOAT)))
CLIPS>
(deffacts users
(user (id 1) (firstname "Mike") (lastname "Mikeson") (username "mike") (average 70.00))
(user (id 1) (firstname "Mike") (lastname "Mikeson") (username "mike") (average 10.00))
(user (id 2) (firstname "John") (lastname "Johnson") (username "john") (average 90.00)))
CLIPS>
(defrule different-averages
(user (username ?un) (average ?avg1))
(user (username ?un) (average ?avg2&:(> ?avg2 ?avg1)))
=>
(println "User " ?un " has averages " ?avg1 " and " ?avg2 "."))
CLIPS> (reset)
CLIPS> (run)
User mike has averages 10.0 and 70.0.
CLIPS>