;; 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 ;; The "registry" is an object that keeps track of all ;; the auto-person objects that need to be given an ;; opportunity to act. (define registry (make-registry)) ;; Here we define the places in the imaginary world of Gack (define food-service (make-place 'food-service)) (define PO (make-place 'PO)) (define alumni-hall (make-place 'alumni-hall)) (define chamber-of-wizards (make-place 'chamber-of-wizards)) (define library (make-place 'library)) (define good-ship-olin (make-place 'good-ship-olin)) (define lounge (make-place 'lounge)) (define computer-lab (make-place 'computer-lab)) (define offices (make-place 'offices)) (define dormitory (make-place 'dormitory)) (define pond (make-place 'pond)) ;; One-way paths connect individual places in the world. (place/add-new-neighbor food-service 'down PO) (place/add-new-neighbor PO 'south alumni-hall) (place/add-new-neighbor alumni-hall 'north food-service) (place/add-new-neighbor alumni-hall 'east chamber-of-wizards) (place/add-new-neighbor alumni-hall 'west library) (place/add-new-neighbor chamber-of-wizards 'west alumni-hall) (place/add-new-neighbor chamber-of-wizards 'south dormitory) (place/add-new-neighbor dormitory 'north chamber-of-wizards) (place/add-new-neighbor dormitory 'west good-ship-olin) (place/add-new-neighbor library 'east alumni-hall) (place/add-new-neighbor library 'south good-ship-olin) (place/add-new-neighbor good-ship-olin 'north library) (place/add-new-neighbor good-ship-olin 'east dormitory) (place/add-new-neighbor good-ship-olin 'up lounge) (place/add-new-neighbor lounge 'west computer-lab) (place/add-new-neighbor lounge 'south offices) (place/add-new-neighbor computer-lab 'east lounge) (place/add-new-neighbor offices 'north lounge) ;; We define persons as follows: ;; We've chosen to define max-the-person rather than ;; redefining max, which is predefined in Scheme to ;; be a procedure for finding the largest of its numeric ;; arguments. (define max-the-person (make-auto-person 'max offices 2)) (define karl (make-auto-person 'karl computer-lab 4)) (define barbara (make-witch 'barbara offices 3)) (define elvee (make-wizard 'elvee chamber-of-wizards 1)) (define player (make-person 'player dormitory)) ;; and now we'll strew some scrolls around: (define scroll-of-enlightenment (make-scroll 'scroll-of-enlightenment)) (place/gain library scroll-of-enlightenment) (for-each (lambda (title) (place/gain library (make-scroll title))) '(crime-and-punishment war-and-peace iliad collected-works-of-rilke)) (define unix-programmers-manual (make-scroll 'unix-programmers-manual)) (place/gain computer-lab unix-programmers-manual) (define next-users-reference (make-scroll 'next-users-reference)) (place/gain computer-lab next-users-reference)