Date 剪辑:计算年龄

Date 剪辑:计算年龄,date,clips,Date,Clips,我需要一个计算年龄的函数。我刚开始学习剪辑。我能算出年数,但答案是错的 (defrule calc-age (person (date-of-birth ?dob)) => (bind ?age (- 2017 ?dob)) (printout t ?age)) CLIPS> (不适用于本年度) ?厘米;当月 ?cd;当日 出生年月 出生月份 出生日 (绑定年龄(--cy-by)) (如果(或((年龄2017 4 6 2016 8 3) 0 剪辑>(年龄2017 4 6 2016

我需要一个计算年龄的函数。我刚开始学习剪辑。我能算出年数,但答案是错的

(defrule calc-age
(person (date-of-birth ?dob))
=>
    (bind ?age (- 2017 ?dob))
(printout t ?age))
CLIPS>
(不适用于本年度)
?厘米;当月
?cd;当日
出生年月
出生月份
出生日
(绑定年龄(--cy-by))
(如果(或(<?cm?bm)
(和(=?cm?bm)(<?cd?bd)))
然后
(绑定年龄(-年龄1)))
?年龄)
剪辑>(年龄2017 4 6 2017 3 2)
0
剪辑>(年龄2017 4 6 2016 8 3)
0
剪辑>(年龄2017 4 6 2016 4 3)
1.
剪辑>(年龄2017 4 6 2016 3 3)
1.
剪辑>(年龄2017 4 6 2015 3 3)
2.
剪辑>
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>