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
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:
(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.
> (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!
Buzzword summary, data structure manipulation functions --
constructors / selectors / recognizers / mutators
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