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: 2.3.3, 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 changes 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) --> not-yet > (watcher) --> Ka-boom!
The special form delay and procedure force allow you to have a lazy evaluation strategy. In particular they can be used to have streams with
(cons-stream a s); a special form the-empty-stream (empty-stream? s) (stream-car s) (stream-cdr s)Streams allow you to conceptually create arbitrarily large sequences, even infinite ones, without wasted computation of producing values in the sequences unless they are actually used. Good stream exercises are 3.53, 3.55
(define (odd-part n) (if (odd? n) n (odd-part (/ n 2)))) (define (3n+1 n) (odd-part (+ 1 (* 3 n)))) (define (triple-3n+1 n) (3n+1 (3n+1 (3n+1 n))))Define a procedure which returns the stream of positive integers k for which (triple-3n+1 k) is greater than k.
Data structure manipulation functions --
constructors / selectors / recognizers / mutators.
Multiple representations of similar data:
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) (accumulate binop unit L) More list processing: (flatten L) (count-pairs L) (map f L1 L2)
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)) -> (biggie 2) Value: 24 -> (biggie 10) Value: 933262154439441526816992388562667004907159682643816214685929638952175999 93229915608941463976156518286253697920827223758251185210916864000000000000000000 000000 ;; 100 factorial