{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS61A_su03_mt1_sol

# CS61A_su03_mt1_sol - (cons(listlast lst(cons(length lst...

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

Summer 2003 CS61A Midterm 1 Solutions Question 1. Part a: (define (remove index lst) (if (= index 1) (cdr lst) (cons (car lst) (remove (- index 1) (cdr lst))))) Part b: (define (remove index lst) (define (helper index lst so-far) (if (= index 1) (append so-far (cdr lst)) (helper (- index 1) (cdr lst) (append so-far (list (car lst))))) (helper index lst '())) Question 2. Part a: (define (make-keeper func) (lambda (sent) (keep func sent))) Part b: (define (make-keeper func) (lambda (sent) (cond ((empty? sent) '()) ((func (first sent)) (se (first sent) ((make-keeper func) (bf sent)))) Summer 2003 CS61A Midterm 1 Solu 1

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

View Full Document
(else ((make-keeper func) (bf sent))))))) Question 3. ;; The perfect solution (define (find-func func-list domain range) (car (filter (lambda (proc) (equal? range (map proc domain))) func-list))) Question 4. (define (superlist lst)
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (cons (listlast lst) (cons (length lst) lst))) (define (superlist-car suplst) (caddr suplst)) (define (suplist-length suplst) (cadr suplst)) (define (suplist-last suplst) (car suplst)) Question 5. (define (adds-to-n? n lst) (cond (( = n 0) true) ((null? lst) false) (else (or (adds-to-n? (- n (car lst)) (cdr lst)) (adds-to-n? n (cdr lst))))). ..) Question 6. Part a: Summer 2003 CS61A Midterm 1 Solu 2 What does (split 'abc) return? ====> (a b) On which line number is the bug that causes this error? =====> 5 What should the fixed line say?=======> (cond ((empty? wd) (se cur)) Part b: There is another bug. On which line is this bug? ======> 6 What should the fixed line say? =======> ((equal? (first cur) (first wd)) Summer 2003 CS61A Midterm 1 Solu 3...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

CS61A_su03_mt1_sol - (cons(listlast lst(cons(length lst...

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

View Full Document
Ask a homework question - tutors are online