SICP Study

5B Computational Objects

Part 1

Recap

Electrical systems

Implementing the primitives

Scheduling delayed tasks

Part 2

Implementing the agenda

Queues

Part 3

Identity of pairs

Highlights

But inadvertent sharing, unanticipated interactions between objects, is the source of most of the bugs that occur in complicated programs. So by introducing this possibility of things having identity and sharing and having multiple names for the same thing, we get a lot of power. But we’re going to pay for it with lots of complexity and bugs. Sussman

Lambda calculus

(define (cons x y)
  (lambda (m)
    (m x y)))
(define (car x) (x (lambda (a d) a)))
(define (cdr x) (x (lambda (a d) d)))
(define (cons x y)
  (lambda (m)
    (m x
       y
       (lambda (n) (set! x n))
       (lambda (n) (set! y n)))))
(define (car x)
  (x (lambda (a d sa sd) a)))
(define (cdr x)
  (x (lambda (a d sa sd) d)))
(define (set-car! x v)
  (x (lambda (a d sa sd) (sa v))))
(define (set-cdr! x v)
  (x (lambda (a d sa sd) (sd v))))