Mercy hospital and the VA hospital have decided to use a common system
to support their patient records. Each hospital keeps a record on new
patients consisting of the patient's name, date of admission, and diagnosis.
However, Mercy uses a list of the form (name date diag), whereas
VA uses (diag name date). In each hospital, many programs deal with these
records, so it is not possible to simply change one to conform to the other.
To handle the combined record keeping system, it is necessary to provide
the constructors \verb|make-Mercy-record| and \verb|make-VA-record| and provide
the generic selectors \verb|name|, \verb|date|, and \verb|diag|.
-
Explain how this can be done using manifest type, but without using a table of
procedures (no put and get).
-
Sketch how you might use data-directed programming, using manifest type and
using put and get on a table of procedures.
The following review sheet is extracted from a final exam review sheet used
in the past. It covers our ground with the exception of the
constraint system (digital circuit simulation) material.
III - Mutable Data
Reading - 293-302.
The bank account example. If a parent procedure (make-account) returns a
child procedure (such as dispatch) defined within it, then the parameters
(such as balance) of the parent procedure are part of the environment of
the child procedure. They can be changed by the child procedure thru the
use of "set!" and are private mutable data objects.
Use of set-car! and set-cdr! in implementing queues and stacks.
When using set-car! and set-cdr!, one must be aware that the pair being changed
may be a part of several lists your program is manipulating. Care must be
taken that such changed do not have unwanted effects on other lists.
For example:
1.
(define x '(1 2 3))
(define y (cons x x))
(set-car! (cdr x) 22)
Now what is x and what is y? Use box and arrow diagrams to understand what
happens.
2. Define a procedure (make-count-down n). It returns a procedure which
decrements a local variable (initial value is n). It returns false, (), if the
variable hasn't reached zero, returns true, #t, if it has.
For example, after you have defined make-count-down, I could have the following:
-> (define counter (make-count-down 3))
Value: counter
-> (define (watcher) (if (counter) 'Ka-boom! 'not-yet))
Value: watcher
-> (watcher)
Value: not-yet
-> (watcher)
Value: not-yet
-> (watcher)
Value: Ka-boom!
Some more good exercises:
set! and local state: 3.1, 3.2, 3.3, 3.4,
set-car! and set-cdr!: 3.12, 3.13, 3.14,
queues: 3.22, 3.23
Buzzword summary, data structure manipulation functions --
constructors / selectors / recognizers / mutators
Reading - Chapter 3, except for pages 214-242 .
II - Data abstraction
Pairs
car cdr / cons / pair? null?
Uses of pairs
abstraction barriers - levels from basic scheme up to application functions
Sequences (lists)
nth length / list append reverse / list?
Symbols and quote '
Symbolic differentition:
Expressions are naturally processed using tree recursion
Simplification is an issue that Make-sum, etc can handle.
-- Homework procedures --
rational numbers:
interval arithmetic:
List processing:
(map f L) (filter p? L) (repeater n) (multilist n)
More list processing:
(atom-count L) (flatten L) (extent L)
Multiple representations
Manifest type
Data directed programming
Some good exercises from chapter 2: 2.18, 2.21, 2.22, 2.23, 2.24
Use of tree strucures. Huffman codes. What they are good for, how
the huffman tree is made, how it is used.
Reading - Chapter 2 excluding 2.2.6 (Huffman codes), 2.4 (Generic operators).
saunders@cis.udel.edu