|
@@ -0,0 +1,83 @@
|
|
|
|
+* Lecture 2B: Computational Objects
|
|
|
|
+https://youtu.be/yedzRWhi-9E
|
|
|
|
+
|
|
|
|
+we can inherit the modularity of the world into our code
|
|
|
|
+
|
|
|
|
+circuits are the best models in physics, according to gjs
|
|
|
|
+
|
|
|
|
+: (define a (make-wire))
|
|
|
|
+: (or-gate a b d)
|
|
|
|
+: etc.
|
|
|
|
+
|
|
|
|
+#+BEGIN_SRC scheme
|
|
|
|
+ (define (half-adder a b s c)
|
|
|
|
+ (let ((d (make-wire)) (e (make-wire)))
|
|
|
|
+ (or-gate a b d)
|
|
|
|
+ (and-gate a b c)
|
|
|
|
+ (inverter c e)
|
|
|
|
+ (and-gate d e s)))
|
|
|
|
+#+END_SRC
|
|
|
|
+
|
|
|
|
+"if a compound object doesn't look like a primitive, there's something
|
|
|
|
+wrong with the language"
|
|
|
|
+
|
|
|
|
+we only have to implement the primitives. means of combination are
|
|
|
|
+gifted by lisp
|
|
|
|
+
|
|
|
|
+this simulator is a real world model that was used to manufacture a
|
|
|
|
+large computer
|
|
|
|
+
|
|
|
|
+AGENDAS
|
|
|
|
+
|
|
|
|
+#+BEGIN_SRC scheme
|
|
|
|
+ (make-agenda)
|
|
|
|
+ (current-time agenda)
|
|
|
|
+ (empty-agenda? agenda)
|
|
|
|
+ (add-to-agenda! time action agenda)
|
|
|
|
+ (first-item agenda)
|
|
|
|
+ (remove-first-item! agenda)
|
|
|
|
+#+END_SRC
|
|
|
|
+
|
|
|
|
+"if im going to change things, i need a place to make the change"
|
|
|
|
+
|
|
|
|
+QUEUE
|
|
|
|
+
|
|
|
|
+can delete from the beg and add to the end
|
|
|
|
+
|
|
|
|
+#+BEGIN_SRC scheme
|
|
|
|
+ (make-queue)
|
|
|
|
+ (insert-queue! queue item)
|
|
|
|
+ (delete-queue! queue)
|
|
|
|
+ (front-queue queue)
|
|
|
|
+ (empty-queue? queue)
|
|
|
|
+#+END_SRC
|
|
|
|
+
|
|
|
|
+--> break
|
|
|
|
+
|
|
|
|
+what makes things the same. what makes things different?
|
|
|
|
+{recall ship of theseus}
|
|
|
|
+
|
|
|
|
+#+BEGIN_SRC scheme
|
|
|
|
+ (define a (cons 1 2))
|
|
|
|
+ (define b (cons a a))
|
|
|
|
+ (set-car! (car b) 3)
|
|
|
|
+#+END_SRC
|
|
|
|
+
|
|
|
|
+"inadverted sharing is the source of most of the bugs in complicated
|
|
|
|
+programs. introducing the possibility of things having identity and
|
|
|
|
+sharing and having multiple names for the same thing, we get a lot of
|
|
|
|
+power but we have to pay for it with lots of complexity and bugs."
|
|
|
|
+
|
|
|
|
+"once you let the camel's nose in the tent, the rest of him follows."
|
|
|
|
+
|
|
|
|
+#+BEGIN_SRC scheme
|
|
|
|
+ (define (cons x y) ;; alonzo
|
|
|
|
+ (λ (m) (m x y))) ;; church's
|
|
|
|
+ (define (car x) ;; hack
|
|
|
|
+ (x (λ (a d) a)))
|
|
|
|
+ (define (cdr x)
|
|
|
|
+ (x (λ (a d) d)))
|
|
|
|
+#+END_SRC
|
|
|
|
+
|
|
|
|
+-- invented by alonzo church "the greatest programmer of the 20th
|
|
|
|
+ century even though he never saw a computer"
|