;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname lec7) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; A list-of-num is either ;; - empty ;; - (make-bigger-list num list-of-num) (define-struct bigger-list (first rest)) ;; fun-on-lon : list-of-num -> ... ;(define (fun-on-lon l) ; (cond ; [(empty? l) ...] ; [(bigger-list? l) ; ... (bigger-list-first l) ; ... (fun-on-lon (bigger-list-rest l)) ...])) ;; aq-weight : list-of-num -> num ;; To add up all the fish weights (define (aq-weight l) (cond [(empty? l) 0] [(bigger-list? l) (+ (bigger-list-first l) (aq-weight (bigger-list-rest l)))])) (check-expect (aq-weight empty) 0) (check-expect (aq-weight (make-bigger-list 2 empty)) 2) (check-expect (aq-weight (make-bigger-list 2 (make-bigger-list 7 empty))) 9) ;; ---------------------------------------- ;; A list-of-num is either ;; - empty ;; - (cons num list-of-num) ;; any-heavy-fish? : list-of-num -> boolean ;; To determine whether any fish in l is ;; at least 10 lbs. ;(define (any-heavy-fish? l) ; (cond ; [(empty? l) ...] ; [(cons? l) ; ... (first l) ; ... (any-heavy-fish? (rest l)) ...]) (define (any-heavy-fish? l) (cond [(empty? l) false] [(cons? l) (or (>= (first l) 10) (any-heavy-fish? (rest l)))])) (check-expect (any-heavy-fish? empty) false) (check-expect (any-heavy-fish? (cons 4 (cons 6 empty))) false) (check-expect (any-heavy-fish? (cons 4 (cons 10 empty))) true) (check-expect (any-heavy-fish? (cons 14 (cons 6 empty))) true)