CS61A                 Summer 2011                 Lab 1B

1. Predict what Scheme will print in response to each of these expressions.  Then  try it and make sure your answer was correct, or if not, that you understand why!

(define  a  3)

(define  b  (+ a 1) )


(+  a  b  (*  a  b) )

(=  a  b)


(if        (and  (>  b  a)  (<  b  (*  a  b) ) )



(cond        ((=  a  4)  6)

((=  b  4) (+  6  7  a)) (else 25))

(+  2  (if  (>  b  a)  b  a))

(*  (cond  ((>  a  b)  a)

((< a b) b) (else  -1))

(+ a 1))

((if  (<  a  b)  +  -)  a  b)


2. In the shell, type the command


cp ~cs61a/lib/plural.scm .


(Note the period  at the end of the line!)  This  will copy a file from the class library  to your own directory. Then, using emacs to edit the file, modify the procedure so that it correctly handles cases like  (plural  ’boy).


3. Define a procedure  that takes three numbers  as arguments and returns the sum of the squares of the two larger numbers.


4. Write a procedure dupls-removed that, given a sentence as input, returns the result of removing duplicate words from the sentence.  Hint:  member? might be useful here...It should work this way:

>  (dupls-removed   ’(a  b  c  a  e  d  e  b))

(c  a  d  e  b)

>  (dupls-removed  ’(a  b  c))

(a  b  c)

> (dupls-removed  ’(a  a  a  a  b  a  a))

(b  a)