Problem Set 6: Hints
If you use the hints, you should indicate them in your sources list. Using the hints will not influence your grade in any way. However, telling us which hints you used will allow us to know which problems were considered difficult. Example: (define sources (list "I used the hints for problems 3 and 7. The hint for problem 3 was helpful, the hint for problem 7 did not help at all."))
In Python:
sources = ["first source", "second source"]
If you can read these words, you are doing it correctly.
Question 1
Hint 1:The neighbor-towards method evaluates to the place that is the neighbor in the requested direction (in this case, a steam tunnel).
Hint 2:
Every object is a procedure: a procedure expecting a message!
Question 3
Hint 1:You need to check if the message is eq? to 'utter.
Hint 2:
If the message is equal to 'utter, you'll want to create an anonymous function that takes two arguments: self and utterance.
Hint 3:
The body of that anonymous procedure should just (display utterance).
Question 4
Hint 1:You'll want to make-sub-object. The parent will be (make-lecturer name). Then you should make an anonymous function that accepts a message as an argument.
Hint 2:
You can ask self 'self and ask self 'lecture if you like.
Hint 3:
If that message is equal to 'profess, you'll want to create an anonymous function that accepts self and thing-to-say as arguments.
Hint 4:
If all else fails, return #f.
Question 5
Hint 1:
Try this to get started:
(define (make-student name)
(make-sub-object
(make-person name)
(let ((is-dressed #t))
(lambda (message)
;;; put code here
Hint 2:
Consider using a case expression on message. You should respond to class, get-undressed!, student?, get-dressed!, and "everything else".
Hint 3:
Here's one way to handle get-dressed! :
((get-dressed!) (lambda (self)
(ask self 'say (list "I feel much better now."))
(set! is-dressed #t)))
Question 6
Hint 1 (restless):Try something like so: (ask super 'make-restless 2) .
Hint 2:
When asked to 'arrest someone, make sure they are in the same place. You can do this with eq? and (ask foo 'location).
Hint 3 (streakers):
You can use other-people-at-place to find other people at your current location. Use filter to find undressed ones.
Hint 4 (clock-tick):
((clock-tick)
(lambda (self)
(let ((streakers ...))
(if (null? streakers)
;;; no one to arrest
;;; else: map "arrest" streakers
Hint 5 ("no longer at"):
If you've got pretty much everything, but your output is different than the expected because garibaldi should be noted as no longer at ... you've probably cut-and-pasted the restlessness wandering code into your code for handling clock ticks. That's not the right idea: object-oriented programming is largely about not copying code. Instead, make-police-officer should ask itself (or its superclass, depending on how you think about it) to set its restlessness to 2 when it's created.
Question 7
Hint 1:Remember that an algorithm is a procedure that is guaranteed to terminate on every possible input.
Hint 2:
Could you define halts? (in a way that is guaranteed to terminate) using streakable? if streakfable? is an algorithm that solves the streakability problem?
Hint 3:
Could you define halts? (in a way that is guaranteed to terminate) using streakable? if streakfable? is an algorithm that solves the streakability problem?
Hint 4:
(define (halts? P)
;;; halts? evaluates to true if evaluating (P) would terminate, and
;;; evaluates to false if evaulating (P) would never terminate.
;;; An arresting-police-officer inherits from police-officer except before
;;; making an arrest it evaluates (P). Hence, if (P) terminates,
;;; the arresting-police-officer makes the arrest normally. If (P) does
;;; not terminate, the arresting-police-officer arrests before making the
;;; arrest, and hence never arrests anyone.
(define (make-arresting-police-officer name)
(make-sub-object
(make-police-officer name)
(lambda (message)
(if (eq? message 'arrest)
(lambda (self arrestee)
(apply-procedure P) ;;; LOOK HERE!
(ask super 'arrest arrestee))
(get-method super message)))))
(let ((aph (make-student 'alyssa-p-hacker)))
(set-up-charlottansville) ;;; We'll use Charlottansville as our world
(install-object (make-arresting-police-officer 'officer-halty) Green)
(install-object aph Green)
(ask aph 'get-undressed!)
(not (streakable?))))
[an error occurred while processing this directive]