(1) Why not use an example like
(cons 100 (cons 55 (cons 123 empty)))My mistake: I broke the rule of using an example from a boundary.
(2) Why not roll all cond-clauses into one:
(define (elim alon) (cond ((empty? alon) empty) (else (cond ((> (first alon) 100) (elim (rest alon))) (else (cons (first alon) (elim (rest alon)))))))) |
(define (elim alon) (cond ((empty? alon) empty) ((> (first alon) 100) (elim (rest alon))) (else (cons (first alon) (elim (rest alon)))))) |
Adam * Eve * |_________| | Mary Louis * |_____| | Ben
How can we represent this in Scheme? Here is one idea.
A family tree is either a - name - (cons F (cons name (cons M empty))) where F is family-tree and M is family-tree.We see a fixed-length list. What should we do? Define constructors and selectors!
(define-struct child (father name mother)) A family-tree is either a - name - (make-child F name M) where F is family-tree and M is family-tree.
Let's translate the example:
(make-family (make-family 'Adam 'Mary 'Eve) 'Ben 'Louis)How many family members? 5.
Let's move on.
(define-struct child (father name mother)) A family-tree is either a - #f - (make-child F name M) where F is family-tree and M is family-tree.
Now let's prune Louis's tree from ours. Who would want to be a descendant of Louis XIV anyway?
Would that have been as easy as that in the previous version?
Choice of data definition matters!
Matthias Felleisen | This page was generated on Fri Apr 9 09:17:38 CDT 1999. |