Description
Textbook references: Chapter 9: Designing with SelfReferential Data Definitions
Warmup
Exercise (Reviewed) 1 Design a data definition for lists of numbers.
Exercise (Reviewed) 2 Design a function anynegatives? that determines if any element in a list of numbers is negative.
Exercise 3 Design a function mean which computes the mean of a list of numbers. Recall that a mean of a group of numbers is its sum divided by its size. Be sure to write a checkerror for when the length of the list is 0.
Exercise 4 Design a function which only keeps the even numbers in a list of numbers.
Exercise 5 Design a function which adds 42 to every element in a listof numbers.
Exercise 6 Design a function intersection which takes in two list of numbers and returns the list of elements appearing in both. member? will be helpful.
Next Slide, Please
Goals: Design a program with lists.
We are going to design a simple slide show program. Every slide will have a title and a list of bullets to display, and each slide and item will be preceded by an event.
Starter code: Below is a data definition which will enable us to build this program.

; – ‘()
; and represents an ordered slideshow
(definestruct slide [title shown hidden])
; and represents a slide’s title, what bullets have been shown, and which are hidden
; – ‘()
; – (cons String LoS)
(define SLIDE1LOS
(cons “Value systems are neat.”
(cons “They help us determine the best ways to live.”
(cons “We each have one.”
(cons “But what value system is best?” ‘())))))
(define SLIDE1 (makeslide “Value Systems” ‘() SLIDE1LOS))
(define SLIDE2LOS
(cons “Picking a best value system requires comparing them.”
(cons “Comparison requires measurement.”
(cons “Sample measurement: which value systems minimizes suffering.”
(cons “But this presents a problem…” ‘())))))
(define SLIDE2 (makeslide “The Best Value Systems” ‘() SLIDE2LOS))
(define SLIDE3LOS
(cons “The minimization of suffering is a value choice.”
(cons “Another one would be maximizing happiness, for example.”
(cons “Any value system measurement is a value system itself.”
(cons “Thus, the best value system cannot ever be determined.” ‘())))))
(define SLIDE3 (makeslide “Value Systems: Axiomatic” ‘() SLIDE3LOS))
(define SLIDESHOW (cons SLIDE1 (cons SLIDE2 (cons SLIDE3 ‘()))))
; slideshowtemp : Slideshow > ?
(define (slideshowtemp slideshow)
(slideshowtemp (rest slideshow)))]))
; slidetemp : Slide > ?
(define (slidetemp slide)
(… (slidetitle slide) (lostemp (slideshown slide)) (lostemp (slidehidden slide))))
; lostemp : LoS > ?
(define (lostemp los)
(lostemp (rest los)))]))
Exercise 7 Design the function drawslide which draws a slide, showing only its title and unhidden content on a large background of a fixed size. The text of the bullets should be arranged above each other.
Exercise 8 Design the function drawslideshow which draws either the slideshow’s first slide or the text “Fin.”, which is always elegant. This should be placed on a large background of a fixed size.
Exercise 9 Design the function advanceslide which moves the first entry in a slide’s hidden content to the end of its shown content if there is any hidden content. Hint: append.
Exercise 10 Design the function slideover? which determines if a slide is over (none of its bullets are hidden).
Exercise 11 Design the function advanceslideshow which either advances its first slide if it has more content to be shown or moves onto the next slide if there is one.
Exercise 12 Design a bigbang program which will advance a slideshow by either a click, a “right” arrow press, or once every two seconds (up to you). The program should end when there are no more slides left.
Before You Go…
If you had trouble finishing any of the exercises in the lab or homework, or just feel like you’re struggling with any of the class material, please feel free to come to office hours and talk to a TA or tutor for additional assistance.
Bullet Hell
Goals: Practice using lists inside structures and structures inside lists.
Exercise 13 Design a function which determines whether or not a given string appears anywhere inside a slideshow. Hint: stringcontains?.
Exercise 14 Design a function which determines the total number of characters in a slideshow.