CLIPS-绑定

一、

1、(bind ?total-area (+ ?total ?area))表示把(+ ?total?area)的结果给?total-area,即绑定。

2、完成求2个矩形的面积之和。

 

二、

1、操作

CLIPS> (unwatch all)
CLIPS> (run)
CLIPS> (reset)
CLIPS> (run)
total=0+8120=8120
total=8120+3800=11920

2、CLP文件

(deftemplate MAIN::rectangle
(slot height)
(slot width))

(deffacts MAIN::rect
(rectangle (height 200) (width19))
(rectangle (height 290) (width28))
(sum 0))

(defrule MAIN::sum-rectangles
(rectangle (height ?height)(width ?width))
=>
(assert (add-to-sum (* ?height?width))))

(defrule MAIN::sum-areas
?sum <- (sum?total)
?new-area <-(add-to-sum ?area)
=>
(retract ?sum ?new-area)
(bind ?total-area (+ ?total?area))
(printout t "total=" ?total"+" ?area "=" ?total-area crlf)
(assert (sum?total-area)))

你可能感兴趣的:(cli)