;; #1 --------------------------------------- ;; in-category? : stock symbol -> boolean ;; is a stock item in a particular category? (define (in-category? a-stock category) (symbol=? category (album-category (stock-album a-stock)))) ;; #2 --------------------------------------- (define-struct update (artist title type change-in-copies change-in-price)) (define u1 (make-update "Beatles" "Abbey Road" 'tape 0 -2)) (define u2 (make-update "Pink Floyd" "The Wall" 'cd 2 0)) (define u3 (make-update "Beatles" "Yellow Submarine" 'cd 0 -2)) (define u4 (make-update "Pink Floyd" "The Wall" 'tape 2 0)) (define u5 (make-update "Beatles" "Abbey Road" 'cd 4 5)) ;; need one that checks update for a stock item ;; apply-update? : an-update a-stock -> boolean ;; determines whether an update applies to a stock item (define (apply-update? an-update a-stock) (and (string=? (update-artist an-update) (album-artist (stock-album a-stock))) (string=? (update-title an-update) (album-title (stock-album a-stock))))) ;; update-format : symbol update format -> format ;; update a format with new inventory information (define (update-format type an-update a-format) (cond [(boolean? a-format) a-format] [else (make-format type (+ (format-copies a-format) (update-change-in-copies an-update)) (+ (format-price a-format) (update-change-in-price an-update)))])) ;; update-stock : update stock -> stock ;; update a stock item with new inventory information (define (update-stock an-update a-stock) (cond [(symbol=? (update-type an-update) 'cd) (make-stock (stock-album a-stock) (update-format 'cd an-update (stock-cd a-stock)) (stock-tape a-stock))] [(symbol=? (update-type an-update) 'tape) (make-stock (stock-album a-stock) (stock-cd a-stock) (update-format 'tape an-update (stock-tape a-stock)))])) ;; update-stock : update stock -> stock ;; update a stock item with new inventory information (define (update-stock an-update a-stock) (cond [(symbol=? (update-type an-update) 'cd) (cond [(boolean? (stock-cd a-stock)) a-stock] [else (make-stock (stock-album a-stock) (make-format 'cd (+ (format-copies (stock-cd a-stock)) (update-change-in-copies an-update)) (+ (format-price (stock-cd a-stock)) (update-change-in-price an-update))) (stock-tape a-stock))])] [(symbol=? (update-type an-update) 'tape) (cond [(boolean? (stock-tape a-stock)) a-stock] [else (make-stock (stock-album a-stock) (stock-cd a-stock) (make-format 'tape (+ (format-copies (stock-tape a-stock)) (update-change-in-copies an-update)) (+ (format-price (stock-tape a-stock)) (update-change-in-price an-update))))])]))