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

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

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
Image of page 1

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

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, not a procedure. (computer 'name) returns a procedure, the method that the object
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern