;; 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-intermediate-lambda-reader.ss" "lang")((modname review2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;; Write a contract and a purpose for this function (define (f list1 list2) (cond [(and (empty? list1) (empty? list2)) empty] [(or (empty? list1) (empty? list2)) (error 'f "The lists must be of equal length")] [else (cons (first list1) (cons (first list2) (f (rest list1) (rest list2))))] ) ) ;; what value will this produce? (f (list 1 2 3) (list 4 5 6)) (define (g list1 list2) (cond [(and (empty? list1) (empty? list2)) empty] [(or (empty? list1) (empty? list2)) (error 'g "The lists must be of equal length")] [else (append (g (rest list1) (rest list2)) (list (first list2) (first list1)))] ) ) ;; what value will this produce? (g (list 1 2 3) (list 4 5 6)) (define-struct mypair (left right)) ;; Write a function that, given a list of mypairs of numbers, creates a list of ;; sums of left and right (define lop (list (make-mypair 2 3) (make-mypair 5 6) (make-mypair 3 7))) ;(sum-pair lop) ;; expected (list 5 11 10) ;; write a function that counts the total number of elements of nested lists ;; of arbitrary nesting ;(number-elements (list 1 2 (list 4 5) (list 3 (list 6)))) ;; expected value 6 ;; Exercise 14.1.4 -- self-referential structures ;; http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-19.html#node_sec_14.1 ;; http://cda.morris.umn.edu/~elenam/1301_fall09/examples/recursive_structures.ss ;; write a function add-bst that adds a node to a binary search tree according ;; to the ordering ;; Exercise 14.2.5 ;; http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-19.html#node_sec_14.2 ;; http://cda.morris.umn.edu/~elenam/1301_fall09/examples/bst.ss