;; 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-intermediate-lambda-reader.ss" "lang")((modname lab10_starter_file) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f))) (define-struct child [name mother father]) ;; Child is a (make-child String AT AT) ;; - name is the child's name ;; - mother is the maternal AncestorTree ;; - father is the paternal AncestorTree ;; AncestorTree (AT) is one of ;; - ‘unknown ;; - (make-child String AT AT) ; EXAMPLES AncestorTree (define Carmen (make-child "Carmen" 'unknown 'unknown)) (define John (make-child "John" 'unknown 'unknown)) (define Joel (make-child "Joel" 'unknown 'unknown)) (define Vladimir (make-child "Vladimir" 'unknown 'unknown)) (define Mike (make-child "Mike" Carmen John)) (define Lucy (make-child "Lucy" Joel Mike)) (define Terrence (make-child "Terrence" Joel Mike)) (define Priscilla (make-child "Priscilla" Lucy Vladimir)) ;; ----------------------------------------------------------------------------- ;; LIBRARY ;; at=?: AT AT -> Boolean ;; given two AT determines if they are the same AT (check-expect (at=? 'unknown 'unkown) #true) (check-expect (at=? Lucy Lucy) #true) (check-expect (at=? Carmen Terrence) #false) (check-expect (at=? Vladimir 'unknown) #false) (define (at=? at1 at2) (cond [(symbol? at1) (symbol? at2)] [else (if (symbol? at2) #false (and (string=? (child-name at1) (child-name at2)) (at=? (child-mother at1) (child-mother at2)) (at=? (child-father at1) (child-father at2))))])) ;; number->ordinal: Number -> String ;; given a number, returns the corresponding ordinal string (check-expect (number->ordinal 1) "1st") (check-expect (number->ordinal 22) "22nd") (check-expect (number->ordinal 12) "12th") (check-expect (number->ordinal 4) "4th") (check-expect (number->ordinal 103) "103rd") (define (number->ordinal n) (local ((define n-string (number->string n)) (define length (string-length n-string)) ; String -> String ; retrieves the last 1String in a String (define (last-string s) (substring s (- length 1) length)) (define suffix (cond [(or (= n 11) (= n 12) (= n 13)) "th"] [(string=? "1" (last-string n-string)) "st"] [(string=? "2" (last-string n-string)) "nd"] [(string=? "3" (last-string n-string)) "rd"] [else "th"]))) (string-append n-string suffix)))