;;; This is one of the example programs from the textbook: ;;; ;;; Artificial Intelligence: ;;; Structures and strategies for complex problem solving ;;; ;;; by George F. Luger and William A. Stubblefield ;;; ;;; These programs are copyrighted by Benjamin/Cummings Publishers. ;;; ;;; We offer them for use, free of charge, for educational purposes only. ;;; ;;; Disclaimer: These programs are provided with no warranty whatsoever as to ;;; their correctness, reliability, or any other property. We have written ;;; them for specific educational purposes, and have made no effort ;;; to produce commercial quality computer programs. Please do not expect ;;; more of them then we have intended. ;;; ;;; Code to run a simple thermostat simulation, ;;; using the oops object oriented programming shell of chapter 15. ;;; ;;; to run the simulation, evaluate the contents of this file, ;;; then evaluate a form such as ;;; ;;; (message 'room-327 'change-temp -5) ;;; ;;; or ;;; ;;; (message 'thermostat-327 'change-setting 70) ;;; (def-object 'thermostat 'object '((setting 65))) (def-object 'room 'object '((temperature 65))) (def-object 'heater 'object '((state 'off))) (def-object 'room-327 'room '((thermostat 'thermostat-327))) (def-object 'thermostat-327 'thermostat '((heater 'heater-327)(location 'room-327))) (def-object 'heater-327 'heater '((location 'room-327))) (def-method 'room 'change-temp #'(lambda (amount-of-change) (let ((new-temp (+ amount-of-change temperature))) (message self 'set-value 'temperature new-temp) (terpri) (prin1 "temperature in ") (prin1 self) (prin1 " changes to ") (prin1 new-temp) (prin1 " degrees.") (terpri) (message thermostat 'check-temp)))) (def-method 'thermostat 'check-temp #'(lambda () (cond ((< (message location 'show-value 'temperature) setting) (message heater 'turn-on)) (t (message heater 'turn-off))))) (def-method 'thermostat 'change-setting #'(lambda (temp) (message self 'set-value 'setting temp) (terpri) (prin1 "New setting of ") (prin1 self) (prin1 " is ") (prin1 temp) (prin1 "degrees.") (terpri) (message self 'check-temp))) (def-method 'heater 'turn-on #'(lambda () (cond ((equal state 'off) (terpri) (prin1 "Heater turns on in ") (prin1 location) (terpri) (message self 'set-value 'state 'on))) (message location 'change-temp 1))) (def-method 'heater 'turn-off #'(lambda () (cond ((equal state 'on) (terpri) (prin1 "Heater turns off in ") (prin1 location) (terpri) (message self 'set-value 'state 'off)))))