Developing Programs for

Developing Programs for - Developing Programs for Family...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Developing Programs for Family Trees c. Kathi Fisler, 2001
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Susan Pat Mike Tom Ann Joe Mary Consider the following family tree: Assuming we want to write programs to query who is in the tree or to count how many generations are in the tree, what data model could we use?
Background image of page 2
Susan Pat Mike Tom Ann Joe Mary Consider the following family tree: • Names • Info about people (name, father, mother) Need to represent: (Will ignore other info, like birthday, for now)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Susan Pat Mike Tom Ann Joe Mary Consider the following family tree: • Names • Info about people (name, father, mother) Need to represent: (use symbols) (use structures)
Background image of page 4
Data Model for Family Trees (define-struct person (name father mother)) • A family tree (ftree) is (make-person symbol ftree ftree) How about: [Try making a family tree with this definition]
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Making Family Trees (define-struct person (name father mother)) • A family tree (ftree) is (make-person symbol ftree ftree) (make-person ‘Mary (make-person ‘Joe ) (make-person ‘Ann (make-person ‘Tom …) (make-person ‘Susan …))) What goes here?
Background image of page 6
Making Family Trees (define-struct person (name father mother)) • A family tree (ftree) is (make-person symbol ftree ftree) (make-person ‘Mary (make-person ‘Joe ) (make-person ‘Ann (make-person ‘Tom …) (make-person ‘Susan …))) What goes here? Follow the data definition! Must use a make-person
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A Broken Family Tree Data Model • Definition requires each parent to be a whole person, with a father and mother (who are also make-persons …) • The definition doesn’t allow finite trees! General rule: every recursive data definition needs at least one non-recursive case (ie, a case with no arrows or with a finite chain of arrows)
Background image of page 8
• A family tree (ftree) is either – ‘unknown – (make-person symbol ftree ftree) A New Data Model for Family Trees (define-struct person (name father mother)) [Try making a family tree with this definition] [notice this case has no arrows]
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sample Family Trees • ‘Hallie • (make-person ‘Mary ‘unknown (make-person ‘Ann ‘unknown ‘unknown)) • (make-person ‘Bernie (make-person ‘Fred (make-person ‘Bubba ‘unknown ‘unknown) ‘unknown)) (make-person ‘Lisa ‘unknown ‘unknown))
Background image of page 10
Programs on Family Trees ;; ftree-func : ftree ! ??? (define (ftree-func aftree) …) How much of this program can you write based on the data definition? [Try it] Suppose we want to write a program on family trees, but I don’t tell you which one …
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Template on Family Trees ;; ftree-func : ftree ! ??? (define (ftree-func aftree) …) What kind of data definition does ftree have?
Background image of page 12
;; ftree-func : ftree ! ??? (define (ftree-func aftree) (cond [… …] [… …]) ) What kind of data definition does ftree have? one based on (two) cases …
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

Developing Programs for - Developing Programs for Family...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online