CSci 1301: Lab 7

You may work in groups of 2 (preferred) or individually.

What to submit

At the end of the lab please send me and your group partner(s) all your Scheme files as e-mail attachments. My e-mail is elenam at morris.umn.edu. The subject of your e-mail must be "1301 Lab 7" followed by "Final" or "Not final", depending on whether this is a final submission or you are still working on it. If you need to finish it, make sure to set up a time with your group partner(s) to finish the lab.

When to submit

Due Monday, November 8th, at 11:59pm. If you submit the final version during the lab, you are done.

Problem 1 (20 points)

Your task is to experiment with a predefined function foldr and then write your own function foldr1 that acts like foldr. The following file gives you the list of examples and tasks:


;; 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

(check-expect (foldr + 0 (list 1 2 3 4 5 6)) 21)
(check-expect (foldr * 1 (list 2 3 4)) 24)
(check-expect (foldr string-append "" (list "apple " "banana " "strawberry")))

;;;;;;;;;;;;;;;;;;;;;;;; Task 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; 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))
;;; Think carefully of what makes sense for the base case here.
;;; You should make an assumption about the range of numbers that you are given
;; expected value 
5

 
;; write your own example of using foldr. Explain (in comments) what 
;; it does

;;;;;;;;;;;;;;;;;;;;;;;; Task 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Write a function foldr1 that acts exactly like foldr 
;; Use above examples as your test cases (don't forget to 
;; change the function name to foldr1)

;; Start by writing a contract


Use Intermediate Student or Intermediate Student with lambda language level for this lab.


CSci 1301 course web site.