Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS61a Midterm #1, Spring 1999, Exams of Computer Engineering and Programming

The cs61a midterm #1 exam from the spring 1999 semester. The exam covers various scheme programming concepts such as recursion, conditional expressions, functions, and procedures. It includes multiple-choice questions that require identifying the output of given scheme expressions, writing procedures, and understanding the behavior of existing procedures.

Typology: Exams

2012/2013

Uploaded on 04/03/2013

shaik_34dd
shaik_34dd 🇮🇳

4.2

(23)

136 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS61a, Spring 1999
Midterm #1
(Total: 20 points)
Question #1 [3 points]
What will Scheme print in response to the following expressions? If an expression produces an error message
or runs forever without producing a result, you may just say "error"; you don't have to provide the exact text
of the message. If the value of an expression is a procedure, just say "procedure"; you don't have to show the
form in which Scheme prints procedures. Assume that no global variables have been defined before entering
these expressions (other than the predefined Scheme primitives).
(word 'for '(no one))
(if (first 'flying) 'yes 'no)
(every (lambda (w) (last (butlast w))) '(think for yourself))
(let ((first last)
(last first))
(first (last '(tomorrow never knows))))
CS61A, Midterm #1, Spring 1999
CS61a, Spring 1999 Midterm #1 1
pf3
pf4
pf5

Partial preview of the text

Download CS61a Midterm #1, Spring 1999 and more Exams Computer Engineering and Programming in PDF only on Docsity!

CS61a, Spring 1999

Midterm

(Total: 20 points)

Question #1 [3 points]

What will Scheme print in response to the following expressions? If an expression produces an error message or runs forever without producing a result, you may just say "error"; you don't have to provide the exact text of the message. If the value of an expression is a procedure, just say "procedure"; you don't have to show the form in which Scheme prints procedures. Assume that no global variables have been defined before entering these expressions (other than the predefined Scheme primitives).

(word 'for '(no one))

(if (first 'flying) 'yes 'no)

(every (lambda (w) (last (butlast w))) '(think for yourself))

(let ((first last) (last first)) (first (last '(tomorrow never knows))))

CS61a, Spring 1999 Midterm #1 1

((lambda (a b c) (word b a c)) '(i want you))

((lambda (a) (a 3)) (lambda (x) (word x x)))

Question #2 [4 points]

Write a procedure n-to-nth that takes a positive integer n as its argument, and returns the value of n ^ n ( n to the n th power), computed by multiplying n by itself n times. Do not use exp, expt, or other mathematical primitives besides +, -, *, and /.

Question #3 [4 points]

Write the procedure select that takes four arguments: a predicate function of one argument, and three sentences, which will all be of equal length. (Reminder: Don't check for errors in the arguments.) Select must return a sentence of the same length as the arguments sentences, in which each word is chosen from the third argument or from the fourth argument depending on whether the predicate, applied to the corresponding word of the second argument, returns true or false. For example:

(select even? '(5 14 32 9) '(she said she said) '(eight days a week)) (EIGHT SAID SHE WEEK)

(se (cross1 (first a) b) (cross (bf a) b))))

(define (cross1 letter wd) (if (empty? wd) '() (se (word letter (first wd)) (cross1 letter (bf wd))))

(a) What is the value of (cross 'get 'back)?

(b) How many calls to cross1 are made in computing the result to part (a)?

(c) Does cross generate an iterative or a recursive process?

(d) Does cross1 generate an iterative or a recursive process?

Question #5 [4 points]

In lecture you saw the example (define (make-adder num) (lambda (x) (+ num x)))

We want to generalize this example, so that we can do to any two-argument procedure what make-adder does to +. You will write a procedure maker-maker for this purpose. Here are some examples of how it should work:

(define (make-adder (maker-maker +)) ((make-adder 3) 5) 8

(define (make-subtracter (maker-maker -)) (define ten-minus (make-subtracter 10)) (ten-minus 3) 7