I am trying to solve this particular exercise from htdp and this how i have done it.<br>;data definition<br>(define-struct child (father mother name date eyes))<br>;oldest generation <br>(define Carl (make-child empty empty 'Carl 1926 'green))<br>
(define Bettina (make-child empty empty 'Bettina 1926 'green))<br><br>;; Middle Generation:<br>(define Adam (make-child Carl Bettina 'Adam 1950 'yellow))<br>(define Dave (make-child Carl Bettina 'Dave 1955 'black))<br>
(define Eva (make-child Carl Bettina 'Eva 1965 'blue))<br>(define Fred (make-child empty empty 'Fred 1966 'pink))<br><br>;; Youngest Generation: <br>(define Gustav (make-child Fred Eva 'Gustav 1988 'brown))<br>
<br><br>;A family-tree-node (short: ftn) is either<br><br> ; 1.<br><br> ; empty; or<br> ;2.<br><br> ; (make-child f m na da ec)<br> ; where f and m are ftns, na<br> ;and ec are symbols, and da is a number.<br>
;contract of eye-color ftn(family tree node) -> list of eyes color <br>;Purpose :This function takes a family tree node and constructs an eye-color list for that node ( eye-color) can occur more.<br>;examples empty -> empty ,carl ->green , bettina -> green , adam->yellow,green, green , dave->black,green,green , gustav-> brown,pink,blue,green,green<br>
;template(define eye-color (lambda (ftn) (cond [(empty? ftn )][else (count-persons (child-father ftn)) (count-persons (child-mother ftn)) (child-name ftn) (child-date ftn) (child-eyes ftn)])))<br>(define eye-color (lambda (ftn)<br>
(cond<br> [(empty? ftn) empty]<br> [else (append(list(child-eyes ftn))(list(eye-color(child-father ftn)))(list(eye-color(child-mother ftn))))])))<br>(eye-color empty)<br>
(eye-color Carl)<br>(eye-color Bettina)<br>(eye-color Adam)<br>(eye-color Gustav)<br><br>empty<br>(list 'green empty empty)<br>(list 'green empty empty)<br>(list 'yellow (list 'green empty empty) (list 'green empty empty))<br>
(list 'brown (list 'pink empty empty) (list 'blue (list 'green empty empty) (list 'green empty empty)))<br><br><br>My question here is :In the question it is asked to use append , and I am appending lists with each other.Is this the right solution ? Also I think cons could have been used to construct a single list for a particulat family-tree-node then why to use append.?<br>
<br><br>Thanks<br><br>Aditya<br><br><br><br>