CISC 280 review sheet for final exam, May 22, 2001

Exam covers entire course with emphasis on chapter 3 and section 4.1

Exam will be similar in structure to the midterm exams and see review guides for midterm exams for sample questions on chapters 1 and 2.

See the web page for summary of lecture topics and various handouts. Covered reading is everything through section 4.1 excluding: 3.5,    2.3.4,    2.5.3,    3.3.4,    3.3.5

Outline

Section 4.1 - Metacircular Evaluator:
Writing eval in Scheme itself, we learn several things.
  1. It is surprisingly short. The core procedures of Scheme need not be extensive programs.
  2. From this implementation we can understand how the environment model really works.
  3. Such implementations (of a language in itself) can serve practical purposes. This can be the most effective way to build more efficient interpreters or compilers, and it can be a way to introduce new special forms into the language.
Chapter 3 - Mutable Data
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, #f, 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))
    --> #unspecified
    > (define (watcher) (if (counter) 'Ka-boom! 'not-yet))
    --> #unspecified
    > (watcher)
    --> not-yet
    > (watcher)
    --> not-yet
    > (watcher)
    --> Ka-boom!
    
  3. 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

Chapter 2 - Data abstraction

Pairs:   cons/ car cdr / pair? null?

Uses of pairs:
   abstraction barriers - levels from basic scheme up to application functions

Sequences (lists):    list append reverse / nth length / list?

Symbols and quote '

Symbolic differentition: Expressions are naturally processed using tree recursion Simplification is an issue that Make-sum, etc can handle.

rational numbers, interval arithmetic:

List processing:    (map f L) (filter p? L) More list processing:    (flatten L) (count-pairs L)

Multiple representations    Manifest type    Data directed programming

Some good exercises from chapter 2: 2.18, 2.21, 2.22, 2.23, 2.24

I - Procedural abstraction

Control -    Repetition (recursion, iteration),
   Selection (cond, if, and, or),
   Sequence - args evaluated before body. sequence in cond clauses, in lambda bodies.

Computing with numbers.
   Use of + - * / quotient remainder
   Use of zero? even? odd? < > = <= >=

Big O.

Procedures as parameters, as returned values.

Exercise: Define a procedure (compose f g). It takes two one-argument procedures f and g and returns a one-argument procedure which for any argument x returns f of g of x. For example, compose could be used thus:

-> (define biggie (compose factorial square))
Value: biggie
-> (biggie 2)
Value:  24
-> (biggie 10)
Value:  933262154439441526816992388562667004907159682643816214685929638952175999
93229915608941463976156518286253697920827223758251185210916864000000000000000000
000000 ;; 100 factorial

The final exam will be similar in structure to the preceeding exams. You can expect some questions similar to (maybe even identical to) questions in previous tests, in homeworks, in the text.