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

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

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

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

View Full DocumentRight Arrow Icon
(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)
Background image of page 2
Background image of page 3
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

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

Page1 / 3

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

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