;; 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 'registry object-class '(list) '(add remove trigger trigger-times)) (class/set-method! registry-class 'init (lambda (this) (object^init this) (registry/set-list! this '()))) (class/set-method! registry-class 'add (lambda (this person) (registry/set-list! this (cons person (registry/get-list this))))) (class/set-method! registry-class 'remove (lambda (this person) (registry/set-list! this (delq person (registry/get-list this))))) (class/set-method! registry-class 'trigger (lambda (this) (for-each auto-person/maybe-act (registry/get-list this)))) (class/set-method! registry-class 'trigger-times (lambda (this n) (if (> n 0) (begin (registry/trigger this) (registry/trigger-times this (- n 1))) 'done)))