Lecture 23 : Two-way family trees ;; A person is a (make-person string famtree famtree list-of-person) (define-struct person (name mother father kids)) ;; A famtree is either ;; - 'unknown, or ;; - a person ;; A list-of-person is either ;; empty, or ;; (cons person list-of-person) Now, create an example family tree for a person named Judy whose mother is named Brenda and whose father is unknown. (define Bper (make-person "Brenda" 'unknown 'unknown empty)) (define Jper (make-person "Judy" Bper 'unknown empty)) (set-person-kids! Bper (list Jper)) ;; add-child-to-mother : person string -> void ;; creates person with given name and the given person as their mother ;; EFFECT: changes kids component of given mother (define (add-child-to-mother mothper cname) (local [(define childper (make-person cname mothper 'unknown empty))] (set-person-kids! mothper (cons childper (person-kids mothper))))) Summary : if two pieces of data need to contain each other, you have to create at least one piece first, define the second to refer to the first, then use set-structure! to make the first refer to the second. ------------------------------------------------------------------- Testing void functions (add-child-to-mother Bper "Eddie") "expects to give Brenda a new child with Brenda as the child's mother" (print the data structure when you're done to prove it's so) --------------------------------------------------------------------