;; 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-abbr-reader.ss" "lang")((modname week3_f) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "htdp"))))) ; A ftn is either ; - empty ; - (make-child symbol number symbol ftn ftn) (define-struct child (name date eyes mom dad)) ;these are going to cause error: (define mary (make-child 'mary 1926 'brown empty empty)) (define peter (make-child 'peter 1926 'blue empty empty)) (define sarah (make-child 'sarah 1965 'green mary peter)) (define orville (make-child 'orville 1966 'orange empty empty)) (define gustav (make-child 'gustav 1990 'blue sarah orville)) ; blue-eyed-ancestor? : ftn -> boolean ; determines if there is a blue-eyed person in family tree (define (blue-eyed-ancestor? a-ftree) (cond [(empty? a-ftree) false] [else (cond [(symbol=? (child-eyes a-ftree) 'blue) true] [else (or (blue-eyed-ancestor? (child-dad a-ftree)) (blue-eyed-ancestor? (child-mom a-ftree)))])])) (check-expect (blue-eyed-ancestor? gustav) true) (check-expect (blue-eyed-ancestor? orville) false) ; template: ;; fun-for-ftn : ftn -> ??? ; (define (fun-for-ftn a-ftree) ; (cond ; [(empty? a-ftree) ...] ; [else ; ... (child-name a-ftree) ... ; ... (child-date a-ftree) ... ; ... (child-eyes a-ftree) ... ; ... (fun-for-ftn (child-dad a-ftree)) ... ; ... (fun-for-ftn (child-mom a-ftree)) ... ;]))