CS 61A         Summer 2011                 Lab 7

1. Modify the person class given in the lecture notes for week 7 (it’s in the file demo2.scm in the

~cs61a/lectures/3.0 directory) to add a repeat method, which repeats the last thing said. Here’s an example of responses to the repeat message.

> (define brian (instantiate person ’brian))

brian

> (ask brian ’repeat)

()

> (ask brian ’say ’(hello))

(hello)

> (ask brian ’repeat)

(hello)

> (ask brian ’greet)

(hello my name is brian)

> (ask brian ’repeat)

(hello my name is brian)

> (ask brian ’ask ’(close the door))

(would you please close the door)

> (ask brian ’repeat)

(would you please close the door)

 

2. This exercise introduces you to the usual procedure described on page 9 of “Object-oriented Programming– Above-the-line View”. Read about usual there to prepare for lab.

Suppose that we want to define a class called double-talker to represent people that always say things twice, for example as in the following dialogue.

> (define mike (instantiate double-talker ’mike))

mike

> (ask mike ’say ’(hello))

(hello hello)

> (ask mike ’say ’(the sky is falling))

(the sky is falling the sky is falling)

 

Consider  the following three definitions for the double-talker class. (They can be found online in the file ~cs61a/lib/double-talker.scm.)

(define-class (double-talker name)

   (parent (person name))

   (method (say stuff) (se (usual ’say stuff) (ask self ’repeat))) )

 

(define-class (double-talker name)

   (parent (person name))

   (method (say stuff) (se stuff stuff)) )

 

(define-class (double-talker name)

   (parent (person name))

   (method (say stuff) (usual ’say (se stuff stuff))) )

 Determine which of these definitions work as intended. Determine also for which messages the three versions would respond differently.