CS61A_fa97_mt1_sol

# CS61A_fa97_mt1_sol - CS 61A Fall 1997 Midterm#1 solutions 0...

This preview shows pages 1–3. Sign up to view the full content.

CS 61A Fall 1997 Midterm #1 solutions 0. Name, etc. Many groups lost this point because they had no identifying information at all on the inside pages. We don't insist on everyone's full name for the group papers, but at least the logins, or the group number, or something! Otherwise when pages get separated it's a big disaster. Many people did not read and/or sign the box on the front that said READ AND SIGN THIS in big bold letters. We didn't take off the question 0 point for that, this time, but we will from now on. 1. What will Scheme print? > (first (bf (first (bf '(back in the ussr))))) N (bf '(back in the ussr)) --> (in the ussr) (first '(in the ussr)) --> in (bf 'in) --> n (first 'n) --> n One common wrong answer, "error," probably came from confusing butfirst with last, or from thinking that a one-letter word doesn't have a first letter. Another common wrong answer was (N) -- a sentence containing the word N. Words and sentences are two different kinds of data; this problem will be seen again in base case errors later in the exam. > '(+ 6 7) (+ 6 7) The value of a quoted sentence is that sentence, even if the sentence looks like a Scheme expression. The value does NOT, however, include the quotation mark. > ((lambda (x y) y) 8 3) 3 Most everyone got this. > (+ '(3 4 5)) ERROR The domain of the + function is numbers, not sentences, not even sentences containing numbers. > (let ((a +) (* 3)) (a * *)) 6 After substitution from the LET, the body means (+ 3 3). The most common mistake was "error," probably because people thought that the symbol * has some special status and can't

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

View Full Document
be a local variable name. There's nothing special about the names of primitives, not even the ones with punctuation characters. > (if 6 7 8) 7 Anything other than #F is true, therefore 6 is true, therefore the IF will evaluate its second argument expression. Scoring: 1/2 point each, rounded down. 2. What kind of process? Recursive. The recursive call provides an argument to a larger expression: (+ n (triangle (- n 1))) When the lower-level TRIANGLE finishes its work, the higher-level one still needs to add its result to N. It's an iterative process only if the higher-level invocation has nothing left to do after the recursive invocation. Most people got this right.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern