; a snake is ; - symbol name ; - number weight ; - symbol food (define-struct snake (name weight food)) ;skinny-snake?: snake -> boolean ; returns true if snake is less than 10 pounds ;( ... (snake-name s) ... ; ... (snake-weight s) ... ; ... (snake-food s) ...) (define (skinny-snake? s) (< (snake-weight s) 10)) (check-expect (skinny-snake? (make-snake 'frank 15 'donuts)) false) ; a dillo is ; - number weight ; - boolean dead (define-struct dillo (weight dead)) ; run-over-with-car: dillo -> dillo ; sets dead in dillo to true ; template: ; ( ... (dillo-weight d) ... ; ...(dillo-dead d))...) (define (run-over-with-car d) ( make-dillo (dillo-weight d) true)) (check-expect (run-over-with-car (make-dillo 15 false)) (make-dillo 15 true)) ; an ant is: ; - number weight ; - posn loc (define-struct ant (weight loc)) ; ant-at-home: ant -> boolean ; returns true if ant is at (0,0) and false ; otherwise ; template: ; (... ( ant-weight a) ... (ant-loc a) ...) (define (ant-at-home a) (at-zero? (ant-loc a))) (check-expect (ant-at-home (make-ant 0.01 (make-posn 0 0))) true) (check-expect (ant-at-home (make-ant 0.01 (make-posn -1 1))) false) ; at-zero? : posn -> boolean ; returns if posn is (0,0) ; (... (posn-x p) ... ; ... (posn-y p) ...) (define (at-zero? p) (and (= (posn-x p) 0) (= (posn-y p) 0) )) (check-expect (at-zero? (make-posn 0 0)) true) (check-expect (at-zero? (make-posn 0 1)) false)