; Jay demistifies COMPUTER. ; transforms Lisp into machinery without intermediate steps. ; "A program is in fact a description of a machine." (DEFINE (GCD A B) (IF (= B 0) A (GCD B (REMAINDER A B)))) ; "One of the important things in designing a computer is, you study ; the problem you want to solve. And then usually what you learn from ; studying the problem you want to solve, is to put the mechanisms ; needed to solve it in the computer you're building. No more and no ; less." --Jay ; Turned into 9A:(6m26s) => 9A:(14m43s) ; section 5-1, TEXINFO document is highly recommended, ; It contains some nice ASCII-diagrams ; for the machine we try to build here. ;; We first define the data paths. ; We have to get B into A (or) B must be written to A. ; We have a box, called REM. It will read A and B. ; It puts out *something*. ; We need to test B if it is 0. (We need a lightbulb ; that ignites if B is 0) ; We actually want swapping of A and B so we need an extra register. ; => 9A:(9m42s) Shows some other versions of swapping, all pretty ; valid... ; A must be written to T before B gets written to A. ; Then T gets written to B. ;; Now we define the controller-part of the machine. ; 9A:(10m40s) "[...] I've got a maze, and the maze has a bunch ; of places connected by directed arrows. ; And what I have is a marble, what is the state of ; the controller, and the marble rolls around in the ; maze. [...] And like in a pin-ball machine it ; *periodically* bumps into buttons. And every so ; often it comes to a place which is a division where ; it has to make a choice, and there is a flap which ; is controlled by a lightbulb." --Jay ; "A really mechanical way of thinking about it..." ; appropriate, analogy. ; 9A:(14m43s) Turning the graphical representation into a ; machine-description language. ; (define-machine gcd ; (registers a b t) ; (controller ; loop (branch (zero? (fetch b)) done) ; (assign t (remainder (fetch a) (fetch b))) ; (assign a (fetch b)) ; (assign b (fetch t)) ; (goto loop) ; done)) ; "LOOKS EASY" 9A:(27m13s) BREAK ; Now we turn recursive processes into machines. (DEFINE (FACT N) (IF (= N 1) N (* N (FACT (- N 1))))) ; "A machine which has a machine inside of it." ; "Of course illusion is all that really matters. If we can arrange ; that every time you look at some infinite object or part of it, ; it is as *infinite* as you need it to be..." --Jay ; Jay introduces the stack on which to place the recursive information ; needed remembered to continue after the last inner machine is done. ; 9A:(34m54s) Construction of the "data paths" and the "lightbulb". ; Then build a stack, on which to place the successive n-values. ; We also need a "continue-register" which stores the address ; to which the process returns on next encounter of CONTINUE. ; The "continue-register" also needs its values stored on the stack. ;(machine fact ;(registers n val) ;(controller ; (assign continue done) ;loop (branch (= 1 (fetch n)) base) ; (save continue) ; (save n) ; (assign n (-1+ (fetch n))) ; (assign continue aft) ; (goto loop) ;aft (restore n) ; (restore continue) ; (assign val (* (fetch n) (fetch val))) ; (goto (fetch continue)) ;base (assign val (fetch n)) ; (goto (fetch continue)) ;done)) ; 9A(44m15s) => 9A:(49m) Simulating with great care... ; QUESTIONS, BREAK ; A little more complex now (Fibonacci): (DEFINE (FIB N) (IF (< N 2) N (+ (FIB (- N 1)) (FIB (- N 2))))) ; to understand the stack a little bit more. ;(assign continue fib-done) ;fib-loop ; N contains ARG, CONTINUE is the recipient. ; (branch (< (fetch n) 2) immediate-ans) ; (save continue) ; (assign continue after-fib-n-1) ; (save n) ; (assign n (- (fetch n) 1)) ; (goto fib-loop) ;after-fib-n-1 ; (restore n) ; ;(restore continue) ; (assign n (- (fetch n) 2)) ; ;(save continue) ; (assign continue after-fib-n-2) ; (save val) ; (goto fib-loop) ;after-fib-n-2 ; (assign n (fetch val)) ;fib(n-2) ; (restore val) ; (restore continue) ; (assign val ; (+ (fetch val) (fetch n))) ; (goto (fetch continue)) ;immediate-ans ; (assign val (fetch n)) ; (goto (fetch continue)) ;fib-done ; 9A:(1h8m) "It's crucial to safe exactly what you need for later." --Jay ; -> "Don't safe more than you need. That leads to disasters." ; 9A:(1h10m12s) The worst that can happen ... ; Jay is pretty good in scaring his audience ... ; ... (END)