Problem 4. You spend your summer consulting for a media conglomerate that owns several radio stations. Much of your code manipulates songs and song play-lists that are represented via the following data definition:
(define-struct song (artist title year)) ;;; A Song is (make-song String String Number) ;;; A List of Songs (LOS) is one of: ;;; - empty ;;; - (cons Song LOS)
Your manager needs the function, @noligsoldies, which takes as its input a list of songs, and returns the list containing all the songs recorded before 1975. Design this function.
;;; Grader: Theo
;;; oldies: LOS -> LOS [1pt]
;;; Filter input, keeping songs recorded before 1975. [1pt]
(define (oldies los)
;; [2pt: for two arms of COND.]
(cond [(empty? los) empty] ; [1pt, for base case]
;; [1pt: nested conditional]
;; [1pt: natural recursion]
;; [1pt: correctness]
[else (cond [(< (song-year (first los)) 1975)
(cons (first los)
(oldies (rest los)))]
[else (oldies (rest los))])]))
;;; Examples/tests: [2pt for a non-trivial example or two examples]
(equal? empty (oldies empty))
(equal? (oldies (cons (make-song "Let it bleed" "Rolling Stones" 1969)
(cons (make-song "Achy breaky heart" "Billy Ray Cyrus"
1992)
empty)))
(cons (make-song "Let it bleed" "Rolling Stones" 1969) empty))