我需要一个计算年龄的函数。我刚刚开始学习 CLIPS 。我可以计算年数,但答案是错误的。
(defrule calc-age
(person (date-of-birth ?dob))
=>
(bind ?age (- 2017 ?dob))
(printout t ?age))
答案 0 :(得分:0)
CLIPS>
(deffunction age (?cy ; current year
?cm ; current month
?cd ; current day
?by ; birth year
?bm ; birth month
?bd) ; birth day
(bind ?age (- ?cy ?by))
(if (or (< ?cm ?bm)
(and (= ?cm ?bm) (< ?cd ?bd)))
then
(bind ?age (- ?age 1)))
?age)
CLIPS> (age 2017 4 6 2017 3 2)
0
CLIPS> (age 2017 4 6 2016 8 3)
0
CLIPS> (age 2017 4 6 2016 4 3)
1
CLIPS> (age 2017 4 6 2016 3 3)
1
CLIPS> (age 2017 4 6 2015 3 3)
2
CLIPS>