CISC 280 review sheet for second midterm exam, November 25, 1996

Exam covers chapters 2 and 3, starting with section 2.2 and extending thru section 3.3 inclusive. Streams will not be covered. Subsections 2.2.5 and 2.2.6 will not be covered. Section 2.4.3 was not covered, the rest of section 2.4 will not be heavily emphasized.

sample question types

  • What is a recognizer? __________
  • What is a constructor? __________
  • What is a proper list? __________
  • What is a generic operator? __________
    The following apply to the lists L = ((1 2) (3 4)) and M = (5 6 7).
  • (append L M) returns __________.
  • (list L M) returns __________.
  • (cons L M) returns __________.
  • (cons (list L (+ 1 3)) (append (list M) M)) returns __________.
  • (cdr (car L)) returns __________.
  • (length (list L M L L M)) returns __________.
  • Write (reverse L), the procedure that returns a list which has the items of L in it, but in reverse order.
  • Write a procedure \verb|split| which takes a list as argument and returns a list of length 2. The two items in this output list are lists. The first one is the list of all the elements of the input list that are in odd numbered positions. The second list is all the elements in even numbered positions.
    > (split (list 1 2 3 4 5 6 7 8 9 0))  ; input may have even length
    ---> ((1 3 5 7 9) (2 4 6 8 0))
    
    > (split (list 1 2 3))  ; input may have odd length
    ---> ((1 3) (2))
    
    > (split (list 1))  ; input may be short
    ---> ((1) ())
    
    > (split '() )  ; input may be very short
    ---> (() ())
    
    > (split (list "a" 1 "b" 77 (* 2 4) "c" '(1 2))) ; it doesn't matter what's in the list 
    ---> (("a" "b" 8 (1 2)) (1 77 "c"))
    
    
  • 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|. 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