CS200: Computer Science, Spring 2002
Notes: Wednesday 27 February 2002
- Now: Exam 1
- Thursday, 28 February, 3:30 in Wilson Hall Room 402: Steven Pinker (MIT Department of Brain and Cognitive Sciences), The Blank Slate, the Noble Savage, and the Ghost in the Machine
- Friday, 8 March: Problem Set 5
- 9-17 March: Spring Break
- Before 18 March: GEB all of Part I
Why is mutation scary?
- (set! Name Expression) evaluate Expression and replace the value associated with Name with the value of Expression
- (set-car! Expression0 Expression1) evaluate Expression0 and Expression1 and store the value of Expression1 in the car part of the value of Expression0. Expression0 must evaluate to a cons pair.
- (set-cdr! Expression0 Expression1) evaluate Expression0 and Expression1 and store the value of Expression1 in the cdr part of the value of Expression0. Expression0 must evaluate to a cons pair.
Why is mutation useful?
Why do our evaluation rules fail when we allow mutation?
Would it be possible to create a circular list without using set-cdr!?
How would you count letters without using mutation?
(define (make-letter-tallys) (for (char->integer #\a) (char->integer #\z) (lambda (accum cno) (append accum (list (cons (integer->char cno) 0)))) null)) (define (count-letters msg) (let ((letter-uses (make-letter-tallys))) (map (lambda (c) (insertlg (lambda (thisletter foundit) (if foundit foundit (if (eq? (car thisletter) c) (begin (set-cdr! thisletter (+ (cdr thisletter) 1)) #t) #f))) letter-uses #f)) (string->list msg)) letter-uses))
University of Virginia
Department of Computer Science
CS 200: Computer Science
Using these Materials