;; 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 foldr) (read-case-sensitive #t) (teachpacks ((lib "testing.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "testing.ss" "teachpack" "htdp"))))) ;; The following predefined function foldr (stands for "fold right") ;; computes a value based on all elements of a list ;; ("folds" a list into a value) ;; the first argument is a function that's applied to the element and the result ;; of the recursive call, the second one is a value for an empty list (base case), ;; the third one is the list (foldr + 0 (list 1 2 3 4 5 6)) ;; expected value 21 (foldr * 1 (list 2 3 4)) ;; expected value 24 (foldr string-append "" (list "apple " "banana " "strawberry")) ;; expected value "apple banana strawberry" ;; fill in the arguments instead of ? according to the definitions: ;; apply foldr to write a function that takes a list of lists ;; and "folds" them into one list ;;(foldr ? ? (list (list 2 3 4) (list 5 6) (list 7) empty)) ;; expected value (list 2 3 4 5 6 7) ;; apply foldr to write a function that takes a list of numbers ;; and finds the maximum value ;(foldr ? ? (list 1 2 3 5 0 -4)) ;; expected value 5 ;; write your own example of using foldr. Explain (in comments) what ;; it does ;; Write a function foldr1 that acts exactly like foldr ;; Use above examples as your test cases (change the function ;; name to foldr1) ;; start by writing a contract