week8 - CS 61A LAB: 1. Week 8 solutions Add REPEAT to...

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

View Full Document Right Arrow Icon
CS 61A Week 8 solutions LAB: 1. Add REPEAT to person class. (define-class (person name) (INSTANCE-VARS (OLD-TEXT '())) (method (say stuff) (SET! OLD-TEXT STUFF) stuff) (method (ask stuff) (ask self 'say (se '(would you please) stuff))) (method (greet) (ask self 'say (se '(hello my name is) name))) (METHOD (REPEAT) OLD-TEXT)) Notice that the ASK and GREET methods don't have to set old-text, because they use the SAY method. 2. Which double-talkers work? (define-class (double-talker name) (parent (person name)) (method (say stuff) (se (usual 'say stuff) (ask self 'repeat))) ) There are two things wrong with this approach. One is that it assumes that the two arguments to SE are evaluated left-to-right, since the use of REPEAT assumes that we've just said the new stuff. That might work in some versions of Scheme but not in others. The second problem is that the value remembered in old-text will be a single copy of the argument, rather than two copies; therefore, if we ask this double-talker to repeat, it'll only say the thing once. (define-class (double-talker name)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/09/2008 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 3

week8 - CS 61A LAB: 1. Week 8 solutions Add REPEAT to...

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

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