#1 STk> (load "proj2/proj2.scm") The computers seem to be down STk> (define dormitory (instantiate place 'dormitory)) dormitory STk> (can-go dormitory 'uphill soda) connected STk> (can-go soda 'downhill dormitory) connected STk> (define comic-relief (instantiate place 'comic-relief)) comic-relief STk> (can-go comic-relief 'east soda) connected STk> (can-go soda 'west comic-relief) connected STk> (define comics (instantiate thing 'comics)) comics STk> (ask comic-relief 'appear comics) appeared STk> (define simon (instantiate person 'simon dormitory)) simon STk> (ask simon 'go 'uphill) simon moved from dormitory to soda appeared STk> (ask simon 'set-talk "give me an A+") STk> (ask simon 'go 'west) simon moved from soda to comic-relief appeared STk> (ask simon 'look-around) (comics) STk> (ask simon 'take comics) simon took comics taken STk> (ask simon 'go 'east) simon moved from comic-relief to soda appeared STk> (ask simon 'go 'up) simon moved from soda to art-gallery appeared STk> (ask simon 'go 'west) simon moved from art-gallery to dyc-office appeared STk> (ask simon 'look-around) (comics brenda david) STk> (ask simon 'notice david) give me an a+ STk> (ask simon 'lose comics) lost STk> (ask david 'take comics) david took comics taken STk> (ask simon 'go 'east) Who's your favorite instructor? Mr. Nobody Who's your favorite instructor? Who's your favorite instructor? David Thanks! simon moved from dyc-office to art-gallery appeared STk> (ask simon 'go 'down) simon moved from art-gallery to soda appeared STk> (ask simon 'go 'down) simon moved from soda to 61a-lab The computers seem to be down appeared STk> (ask hacker 'go 'up) The workstations come back to life just in time. hacker moved from 61a-lab to soda appeared STk> (ask simon 'look-around) () #2A david is a procedure takes one arguement, that is message. proof: STk> david #[closure arglist=(message) 1a3c00] #2B default message by instance-vars: direction-and-neighbors things people entry-procs exits-procs message defined by method (arguement list enclosed in ()): type place? may-enter? neighbors exits look-in (message) appear (new-things) enter (new-person) gone (thing) exit (person) new-neighbor (direction neighbor) add-entry-procedure (proc) add-exit-procedure (proc) remove-entry-procedure (proc) remove-exit-procedure (proc) clear-all-procs also: the method put and default-method in the parent class basic-object #2C STk> (ask david 'go 'south) david moved from sproul-plaza to telegraph-ave There are tie-dyed shirts as far as you can see... appeared STk> (ask david 'exits) (east south north) STk> (ask david 'go 'east) david moved from telegraph-ave to peoples-park appeared STk> (ask david 'place) #[closure arglist=(message) 279f68] STk> (define (whereis people) (ask (ask people 'place) 'name)) whereis STk> (whereis david) peoples-park STk> (ask peoples-park 'appear bagel) *** Error: unbound variable: peoples-park Current eval stack: __________________ 0 (ask peoples-park (quote appear) bagel) explaination: (instantiate place 'peoples-park) returns a new procedure which is an instance of place, the name local to this instance is 'peoples-park. Yet, we have not give this instance a name, instead, we just connects it to the east of telegraph-ave, but remember that's a one way path, no way for david to return to telegraph-ave once he enter the place which local variable name is 'peoples-park (ask david 'place) gives a procedure which is the value of (instantiate place 'peoples-park) I made that let statement into a procedure, named whereis, take a person as an arguement, and return the name of the place where the person is. when we ask david, it returns 'peoples-park. This makes sense because the local variable name bound to (instantiate place 'peoples-park) is 'peoples-park. we get an error when we try to call (ask peoples-park 'appear bagel). The reason is that peoples-park is not the the same as (instantiate place 'peoples-park), the 'peoples-park is not the name of this new instance, but the local variable name bound to this instance. One way to correct is to say (ask (ask david 'place) 'appear bagel) STk> (define bagel (instantiate thing 'bagel)) bagel STk> (ask (ask david 'place) 'appear bagel) appeared STk> (ask david 'look-around) (bagel comics) #2D STk> (eq? (ask telegraph-ave 'look-in 'east) (ask david 'place)) #t STk> (eq? (ask david 'place) 'peoples-park) #f STk> (eq? (ask (ask david 'place) 'name) 'peoples-park) #t STk> (define computer (instantiate thing 'durer)) computer STk> (ask 61a-lab 'appear computer) appeared this one is correct, the rest is incorrect computer is defind as (instantiate thing 'durer), and this instance of thing named computer is added to the instance-vars things in 61a-lab STk> (ask 61a-lab 'appear durer) *** Error: unbound variable: durer Current eval stack: __________________ 0 (ask 61a-lab (quote appear) durer) error because durer is undefined, 'durer is the value of the local variable name bound to the computer, an instance of thing STk> (ask 61a-lab 'appear 'durer) appeared this one seems fine, but it is a BIG BUG, let's see what happen if we give the following command STk> (ask 61a-lab 'things) (durer #[closure arglist=(message) 254648]) now, strange things happened, this call should give a list of procedure to present the things at 61a-lab, but we have 'durer inside now hacker is in 61a-lab, ask him to look around STk> (ask hacker 'look-around) *** Error: eval: bad function in : (object message) Current eval stack: __________________ 0 (object message) 1 (let ((method (object message))) (if (method? method) (apply method args) (error "No method" message (cadr method)))) 2 (map (lambda (obj) (ask obj (quote name))) (filter (lambda (thing) (not (eq? thing self))) (append (ask place (quote things)) (ask place (quote people))))) now, we have an error because there is no way to find the name bound by 'durer STk> (computer 'name) #[closure arglist=() 284188] STk> ((computer 'name)) durer ;(computer 'name) gives a procedure, which is defined in definition of thing. ;the exact procedure should be (lambda () name), which is proved by the call ;((computer 'name)) gives 'durer which is the name of computer. #2E (define-class (thing name) (instance-vars (possessor 'no-one)) (method (name) name) (method (possessor) possessor) (method (type) 'thing) (method (change-possessor new-possessor) (set! possessor new-possessor))) some late exercises require more changes, please refer to the definition of thing in adv.scm #2F (define (whereis people) (ask (ask people 'place) 'name)) (define (owner thing) (let ((f (ask thing 'possessor))) (if (word? f) f (ask f 'name)))) STk> (owner comics) david STk> (whereis simon) art-gallery ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PART I, MEMEBER A ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #A3 with the proper modifications to adv-world.scm, the execution result is: STk> (load "proj2/proj2.scm") The computers seem to be down STk> (define jason (instantiate person 'jason s-h)) Miles and miles of students are waiting in line... jason STk> (ask jason 'go 'west) *** Error: You can check out any time you'd like, but you can never leave Current eval stack: __________________ 0 (stk-error "~A" (with-output-to-string (lambda () (for-each (lambda (x) (display x)) args)))) 1 (for-each (lambda (proc) (proc)) exit-procs) 2 (apply method args) 3 (cond ((null? new-place) (error "Can't go" direction)) (else (ask place (quote exit) self) (announce-move name place new-place) (for-each (lambda (p) (ask place (quote gone) p) (ask new-place (quote appear) p)) possessions) (set! place new-place) (ask new-place (quote enter) self))) STk> (ask jason 'go 'west) *** Error: You can check out any time you'd like, but you can never leave Current eval stack: __________________ 0 (stk-error "~A" (with-output-to-string (lambda () (for-each (lambda (x) (display x)) args)))) 1 (for-each (lambda (proc) (proc)) exit-procs) 2 (apply method args) 3 (cond ((null? new-place) (error "Can't go" direction)) (else (ask place (quote exit) self) (announce-move name place new-place) (for-each (lambda (p) (ask place (quote gone) p) (ask new-place (quote appear) p)) possessions) (set! place new-place) (ask new-place (quote enter) self))) STk> (ask jason 'go 'west) *** Error: You can check out any time you'd like, but you can never leave Current eval stack: __________________ 0 (stk-error "~A" (with-output-to-string (lambda () (for-each (lambda (x) (display x)) args)))) 1 (for-each (lambda (proc) (proc)) exit-procs) 2 (apply method args) 3 (cond ((null? new-place) (error "Can't go" direction)) (else (ask place (quote exit) self) (announce-move name place new-place) (for-each (lambda (p) (ask place (quote gone) p) (ask new-place (quote appear) p)) possessions) (set! place new-place) (ask new-place (quote enter) self))) STk> (ask jason 'go 'west) You may leave now jason moved from sproul-hall to sproul-plaza appeared #A4a testing result with the proper modification in (method (enter new-person)) STk> (define simon (instantiate person 'simon soda)) simon STk> (ask simon 'set-talk "Hey, where am I?") STk> (define singer (instantiate person 'rick sproul-plaza)) singer STk> (ask singer 'set-talk "My funny Valentine, sweet comic valentine") STk> (define preacher (instantiate person 'preacher sproul-plaza)) My funny Valentine, sweet comic valentine preacher STk> (ask preacher 'set-talk "Praise the Lord") STk> (define street-person (instantiate person 'harry telegraph-ave)) There are tie-dyed shirts as far as you can see... street-person STk> (ask street-person 'set-talk "Brother, can you spare a buck") STk> (whereis simon) soda STk> (ask simon 'go 'south) simon moved from soda to lewis appeared STk> (ask simon 'go 'south) simon moved from lewis to sproul-plaza Praise the Lord My funny Valentine, sweet comic valentine appeared STk> (ask simon 'go 'south) simon moved from sproul-plaza to telegraph-ave Brother, can you spare a buck There are tie-dyed shirts as far as you can see... appeared STk> (ask simon 'notice street-person) Hey, where am I? #A4b result with the locked-place class defined in adv.scm and the instance heaven defined in adv-world.scm STk> (define simon (instantiate person 'simon soda)) simon STk> (ask simon 'exits) (death south down up) STk> (ask simon 'go 'death) heaven locked STk> (ask heaven 'unlock) STk> (ask simon 'go 'death) simon moved from soda to heaven appeared STk> (whereis simon) heaven ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PART I, MEMBER B ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #B3 STk> (define katie (instantiate person 'katie soda)) katie STk> (define jack (instantiate person 'jack soda)) jack STk> (define coke (instantiate thing 'coke)) coke STk> (define pepsi (instantiate thing 'pepsi)) pepsi STk> (define rat (instantiate thing 'rat)) rat STk> (define cat (instantiate thing 'cat)) cat STk> (ask soda 'appear coke) appeared STk> (map (lambda (a) (ask soda 'appear a)) (list pepsi rat cat)) (appeared appeared appeared) STk> (ask katie 'look-around) (cat rat pepsi coke jack) STk> (ask jack 'take rat) jack took rat taken STk> (ask katie 'take-all) katie took cat katie took pepsi katie took coke (taken taken taken) STk> (map (lambda (a) (owner a)) (list rat cat pepsi coke)) (jack katie katie katie) #B4a STk> (ask david 'strength) 100 STk> (ask katie 'strength) 100 STk> (ask jack 'strength) 100 STk> (ask david 'put 'strength 90) ok STk> (ask david 'strength) 90 STk> (ask david 'money) #f #B4b STk> (ask david 'place?) #f STk> (ask david 'person?) #t STk> (ask david 'thing?) #f STk> (ask soda 'person?) #f STk> (ask soda 'thing?) #f STk> (ask soda 'place?) #t STk> (ask coke 'thing?) #t STk> (ask coke 'place?) #f STk> (ask coke 'person?) #f