proj3a - CS 61A Project 3 solutions(Part I(You have to 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 CS 61A Project 3 solutions (Part I) 1. Let's say you live in Bowles, which is east of Lewis. (You have to work a little harder if you live on Southside!) (define Bowles (instantiate place 'Bowles)) (can-go Lewis 'east Bowles) (can-go Bowles 'west Lewis) (define student (instantiate person 'Nerdbert Bowles)) (define Kirin (instantiate place 'Kirin)) (can-go Soda 'north Kirin) (can-go Kirin 'south Soda) (define potstickers (instantiate thing 'potstickers)) (ask Kirin 'appear potstickers) (ask student 'go 'west) (ask student 'go 'north) (ask student 'go 'north) (ask student 'take potstickers) (ask student 'go 'south) (ask student 'go 'up) (ask student 'go 'west) (ask student 'lose potstickers) (ask Brian 'take potstickers) (ask student 'go 'east) (ask student 'go 'down) (ask student 'go 'down) 2A. Abstractly, Brian is an object, an instance of the class Person. Objects are represented using procedures, so if you print Brian you'll see Scheme's representation of a procedure. 2B. The messages that a PLACE understands are the ones for which methods or variables are defined in the PLACE class definition: name, directions-and-neighbors, things, people, entry-procs, exit-procs, type, neighbors, exits, look-in, appear, gone, new-neighbor, enter, exit, add-entry- procedure, add-exit-procedure, remove-entry-procedure, remove-exit-procedure, clear-all-procs. Note: If the PLACE class definition included a PARENT clause, then a PLACE Page 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 would also understand the parent class's messages. 2C. We have moved Brian to a place named Peoples-Park that isn't the value of any variable. [That is, there's no (define Peoples-Park . ..).] (ask Brian 'place) returns #<procedure>, an object. (let ((where (ask Brian 'place))) (ask where 'name)) returns Peoples-Park, the symbol that the place procedure remembers as its internal name for itself. (ask Peoples-Park 'appear bagel) gives an error message saying that there is no binding for the variable name Peoples-Park. The point is that there are two different things you could consider the name of the place. One is its INTERNAL name, the value of its internal NAME variable. The other is its EXTERNAL name, a global Scheme variable whose value is the object. If we say something like (define Peoples-Park (instantiate place 'Peoples-Park)) then the two names are the same, but if we say (define s-h (instantiate place 'Sproul-Hall)) then the two names are different. If, as in this problem, we say (can-go Telegraph-Ave 'east (instantiate place 'Peoples-Park)) then there is no external name for the place. If we wanted to put a pizza in People's Park we'd then have to say something like (ask (ask Telegraph-Ave 'look-in 'east) 'appear Pizza) 2D. (ask 61a-lab 'appear computer) is correct because the argument to the appear procedure is supposed to be a procedure object that represents a thing. COMPUTER is bound in the global environment to just such a procedure object, whereas DURER is unbound and 'DURER evaluates to a symbol,
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2009 for the course CS 61A taught by Professor Harvey during the Fall '08 term at Berkeley.

Page1 / 25

proj3a - CS 61A Project 3 solutions(Part I(You have to 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online