CS61A_fa97_mt1_sol

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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. Scoring: 1 point!
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2010 for the course CS 61A taught by Professor Harvey during the Fall '08 term at Berkeley.

Page1 / 6

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

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

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