lab1 - CS 61A FIRST LAB: Week 1 Lab Solutions No problems...

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

View Full Document Right Arrow Icon
CS 61A Week 1 Lab Solutions FIRST LAB: No problems that required original solutions! SECOND LAB: 1. Nothing original. 2. If the last letter is Y, then we have to look at the next-to-last: (define (plural wd) (if (and (equal? (last wd) 'y) (not (vowel? (last (bl wd))))) (word (bl wd) 'ies) (word wd 's))) If you didn't think to use AND in that way, it can be done with nested IFs: (define (plural wd) (if (equal? (last wd) 'y) (if (vowel? (last (bl wd))) (word wd 's) (word (bl wd) 'ies)) (word wd 's))) Or, if that's too messy, with a subprocedure: (define (plural wd) (if (equal? (last wd) 'y) (y-plural (bl wd)) (word wd 's))) (define (y-plural prefix) (if (vowel? (last prefix)) (word prefix 'ys) (word prefix 'ies))) All of these assume the definition of vowel? in the handout. 3. There are, of course, many possible ways to write this. None is perfectly elegant. The difficulty is figuring out which of the three arguments is smallest, so you can leave it out of the computation. The way I like best, I think, is a little tricky:
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 note was uploaded on 05/12/2010 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 2

lab1 - CS 61A FIRST LAB: Week 1 Lab Solutions No problems...

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