CLIPS пример программы - gas

[другие примеры программ на CLIPS ]

(defclass gas-water-automate
  (is-a USER)
  (role concrete)
  (pattern-match reactive)
  (slot gas-water (type INTEGER) (create-accessor read-write))
  (slot syrup (type INTEGER) (create-accessor read-write))
)

(definstances automates
  (our-automate of gas-water-automate
    (gas-water 2)
    (syrup 3)
  )
)

(defmessage-handler gas-water-automate getwater (?money)
  (if (= ?money 1) then
    (if (> (dynamic-get gas-water) 0) then
      (dynamic-put gas-water (- (dynamic-get gas-water) 1))
      (printout t "Your gas-water, please" crlf)
    else
      (printout t "Sorry, no more gas-water" crlf)
    )
  else
    (if (= ?money 3) then
      (if (and (> (dynamic-get gas-water) 0) (> (dynamic-get syrup) 0)) then 
        (dynamic-put gas-water (- (dynamic-get gas-water) 1))
        (dynamic-put syrup (- (dynamic-get syrup) 1))
        (printout t "Your gas-water with syrup, please" crlf)
      else
        (printout t "Sorry, no more gas-water or syrup" crlf)
      )
    else
      (printout t "Wrong money" crlf)
    )
  )
)

(defrule drinkwater
  (money ?money)
  =>
  (send [our-automate] getwater ?money)
)