
COSC 3015
Practice MidTerm Examination
1. (15 pts) Given the function defintions below, use block structure to hide the
definitions of y and sum in ss. Remove all parameters that, because of lexical
scoping, no longer need to be passed.
(define (y k a f h) (f (+ a (* h k))))
(define (sum k result h a f)
(if (< k 1)
result
(sum (- k 1) (+ result (* (if (even? k) 2 4) (y k a f h))))))
(define (ss f a b n)
(let ((h (/ (- b a) n)))
(* (/ h 3.0) (+ (y 0 a f h)(sum n 0 h a f)(y n a f h)))))
2. (20 pts) Given the function
(define (find item L test)
(cond ((null? L) nil)
((test item (car L)) L)
(else (find item (cdr L) test))))
Use the substitution model and applicative-order evaluation to determine the value of
the following expression. Show every substitution step.
(find ‘a ‘((e f t) (r a x) (e r)) memq)