;; This file contains excerpts from the textbook Concrete ;; Abstractions: An Introduction to Computer Science Using Scheme, by ;; Max Hailperin, Barbara Kaiser, and Karl Knight, Copyright (c) 1998 ;; by Brooks/Cole Publishing Company. This file may not be reproduced ;; or redistributed other than for use with that textbook. ;; Chapter 14: Object-Oriented Programming ;; 14.5 An Application: Adventures in the Imaginary Land of Gack (define-class 'witch auto-person-class '() '(curse)) (class/set-method! witch-class 'act (lambda (this) (let ((victim (random-element (witch/other-people-at-same-place this)))) (if victim (witch/curse this victim) (auto-person^act this))))) (class/set-method! witch-class 'curse (lambda (this person) (let ((person-name (person/name person))) (person/say this (list "Hah hah hah, I'm going to turn you into a frog" person-name)) (turn-into-frog person) (person/say this (list "Hee hee" person-name "looks better in green!"))))) (define turn-into-frog (lambda (person) (for-each (lambda (item) (person/lose person item)) (person/possessions person)) (person/say person '("Ribbitt!")) (person/move-to person pond) (registry/remove registry person)))