;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-reader.ss" "lang")((modname lect06c-) (read-case-sensitive #t) (teachpacks ((lib "universe.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.ss" "teachpack" "2htdp"))))) ; data def'n: ; an anc-tree (ancestor tree) is: ; - 'unknown ; - (make-child [string] [int] [symbol] [anc-tree] [anc-tree]) (define-struct child (name yob eye ma pa)) ; examples of data of anc-tree: 'unknown (define lieselotte (make-child "Lieselotte" 1915 'green 'unknown 'unknown)) (define kristin (make-child "Kristin" 1943 'blue lieselotte 'unknown)) (define gordon (make-child "Gordon" 1938 'brown (make-child "Lois" 1899 'brown 'unknown 'uknown) (make-child "George" 1894 'blue 'unknown 'uknown))) (define ian (make-child "Ian" 1966 'blue kristin gordon)) ;; fun-for-anc-tree : anc-tree --> ??? ;; ;(define (fun-for-anc-tree anc) ; (cond [(symbol? anc) ...] ; [(child? anc) ...(child-name anc) ; ...(child-yob anc) ; ...(child-eye anc) ; ...(fun-for-anc-tree (child-ma anc)) ; ...(fun-for-anc-tree (child-pa anc))]) (define (size anc) (cond [(symbol? anc) 0] [(child? anc) (+ (size (child-ma anc)) (size (child-pa anc)) 1)])) (check-expect (size 'unknown) 0) (check-expect (size lieselotte) 1) (check-expect (size kristin) 2) (check-expect (size gordon) 3) (check-expect (size ian) 6) ; rename-all : anc-tree string -> anc-tree ; (define (rename-all anc newname) (cond [(symbol? anc) 'unknown] [(child? anc) (make-child newname (child-yob anc) (child-eye anc) (rename-all (child-ma anc) newname) (rename-all (child-pa anc) newname))])) ; Return all the children in a tree. ; get-all-children : anc-tree -> (listof child) (define (get-all-children anc) (cond [(symbol? anc) empty] [(child? anc) (append (get-all-children (child-ma anc)) (list anc) (get-all-children (child-pa anc)))]) ; challenge: write my-append. ; (Hint: follow the template for a list, ; but only take first/rest of arg1.)