;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname review_final) (read-case-sensitive #t) (teachpacks ((lib "testing.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "testing.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))))) ;; Write a contract and purpose for this function (define (build-range x y a-function) (cond [(= x y) (list (a-function x))] [else (cons (a-function x) (build-range (+ x 1) y a-function))] ) ) ;; what will be the result of this call? (build-range 2 10 (lambda (x) (/ x 2))) ;; write a function that takes 4 parameters: start, end, increment, ;; and a function and returns a list of results of the functions ;; applied to: start, start + inc, start + 2* inc, ... start + n * inc ;; where start + n * inc is the last value <= end ;; use of map, filter, etc ;; find the sum of squares of odd numbers from 1 to 10 using only predefined ;; functions (map, filter, build-list, foldr, etc) ;; use of predefined functions with structures (list (make-posn -2 3) (make-posn 4 5) (make-posn -1 -5)) ;; use the predefined functions to filter out all position ;; in which x and y have different signs ;; which of the following functions are tail-recursive? ;; rewrite those that aren't as tail-recursive (define (last a-list) (cond [(empty? a-list) (error 'last "No last element in an empty list")] [(empty? (rest a-list)) (first a-list)] [else (last (rest a-list))] ) ) (check-expect (last (list 1 2 3 4 5)) 5) (define (all-greater lon1 lon2) (cond [(or (empty? lon1) (empty? lon2)) true] [(>= (first lon1) (first lon2)) (all-greater (rest lon1) (rest lon2))] [else false] ) ) (check-expect (all-greater (list 4 5 6) (list 1 2 3)) true) (check-expect (all-greater (list 4 5 6) (list 1 7 3)) false) (define (greater lon1 lon2) (cond [(empty? lon1) lon2] [(empty? lon2) lon1] [(>= (first lon1) (first lon2)) (cons (first lon1) (greater (rest lon1) (rest lon2)))] [else (cons (first lon2) (greater (rest lon1) (rest lon2)))] ) ) (check-expect (greater (list 4 5 6) (list 1 2 3)) (list 4 5 6)) (check-expect (greater (list 4 5 6) (list 1 7 3)) (list 4 7 6)) ;; write a function two-lists-function-builder that ;; takes two lists and a function of two parameters ;; and returns a function that can be applied to two lists ;; of equal length and return a list of the results of ;; element-wise application of the function ;; example: (define sum-lists (two-lists-function-builder +)) ;; (sum-list (1 2 3) (3 2 1)) -> (4 4 4) ;; memory update ;; what will be the result? (define x 2) (define y 1) (set! x (+ x 2)) (begin (set! x -1) (set! y (+ x y)) (* x y))