- SICP OpenCourse 6 : L5B-P1~P3-Co
- SICP OpenCourse 1 : L1A Overview
- SICP OpenCourse 7 : L6A-Stream I
- SICP OpenCourse 8 : L6B-Stream I
- SICP OpenCourse 9 : L7A-Metacirc
- SICP OpenCourse 13 : L9A-Registe
- SICP OpenCourse 2 : L1B Processe
- SICP OpenCourse 15 : L10B-Storag
- SICP OpenCourse 10 : L7B-Metacir
- SICP OpenCourse 11 : L8A-Logic P
SICP OpenCourse (Structure and Interpretation of Computer Programs)
PART 1
1.POINT: A SIMULATOR FOR DIGITAL CIRCUITS
- Build a new language emended in LISP
- Key point is implementing a Primitive. Like MetaNet which embedding in Bitcoin, implement a Primitive (Node) by Tx.
- What is the essential of Embedding? Is or not use the same Material of Primitive from the new language and original language.
2.PRIMITIVES AND MEANS OF COMBINATION
(define a (make-wire))
(define b (make-wire))
(define c (make-wire))
(define d (make-wire))
(define e (make-wire))
(define s (make-wire))
(or-gate a b d)
(and-gate a b c)
(inverter c e)
(and-gate d e s)
- We're going to build up an invented language in Lisp, embedded in the same sense that Henderson's picture language was embedded, which is not the same sense as the language of pattern match and substitution was done yesterday.
- The pattern match substitution language was interpreted by a Lisp program
- But the embedding of Henderson's program is that we just build up more and more procedures that encapsulate the structure we want.
3.MEANS OF ABSTRACTION
(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)
'OK))
4.LANGUAGE ITERM
- So we have a language so far, That has primitives, means of combination, and means of abstraction to real language.
- Now, how are we going to implement this?
- The only problem is we have to implement the primitives
- Nothing else has to be implemented, because we're picking up the means of combination and abstraction from Lisp, inheriting them in the embedding.
- My understanding: Metanet is embedded in Bitcoin :
1.Primitives => Primitive is TX itself.
2.Inheriting => use TX to Inheriting.
5.IMPLEMENTING A PRIMITIVE
(define (inverter input output)
(define (invert-input)
(let ((new-value (logical-not (get-signal input))))
(after-delay inverter-delay
(lambda()
(set-signal! output new-value)))))
(add-action! input invert-input)
'OK)
(define (logical-not s)
(cond ((= s 0) 1)
((= s 1) 0)
(else (error "Invalid signal" s))))
(define (make-wire)...
6.WIRE=>A MESSAGE ACCEPTING OBJECT, Message-passing style
- Which accepts a message like, "What's your method of adding action procedures?"
- That it'll give me a procedure, which is the ADD-ACTION-PROCEDURE, which I can then apply to an action procedure to create another action procedure in the wire.
- So that's a permission. So it's given me permission to change your action procedures.
(define (make-wire)
(let ((signal-value 0)(action-procedures 'c)))
(define (set-my-singnal! new-value))
(... (call-each action-procedures)... 'done))
(define (accept-action-procedure! proc)
(set! action-procedures (cons proc action-procedures))
(proc))
(define (dispatch m)
(cond ((eq? m 'get-signal) singal-value)
((eq? m 'set-signal!) set-my-signal!)
((eq? m 'add-action!) accept-action-procedure!)
(dispatch))
PART 2
1.PURPOSE=> A WAY OF ORGANIZING TIME AGENDA OR PRIORITY QUEUE.
AGENDAS:
(MAKE-AGENDA) => new agenda
(CURRENT-TIME agenda) => time
(EMPTY-AGENDA? agenda) => true/false
(ADD-TO-AGENDA! time action agenda)
(FIRST-TIME agenda) => action
(REMOVE-FIRST-ITEM agenda)
- An agenda is going to be some kind of list, be able to modify.
- It's organized by time. It's probably good to keep it in sorted order
- I'm going to make an agenda as a list of segments.
2.A DATA STRUCTURE FOR AN AGENDA
- We can build any structure by pair.
3.QUEUE
(MAKE-QUEUE) => new queue
(INSERT-QUEUE! queue iterm)
(DELETE-QUEUE! queue) // "!" change something
(FRONT-QUEUE queue)
(EMPTY-QUEUE? queue) // "?" test is
4.STRUCTURE FOR QUEUE
- I need a certain number of new primitive operations. to control queue's elements
(set-car! <pair> <value>)
(set-cdr! <pair> <value>)
PART 3
5.PURPOSE: GET NEW VERSION CONS WITH NEW PROCEDURE SET-CAR! AND SET-CDR!
- Pairs made by cons, we only said a few axioms about them:
(car (cons x y)) = x
(cdr (cons x y)) = y
- Now, there say nothing about whether a CONS has identity like a person. In fact, all they say is something sort of abstract. that a CONS is the parts it's made out of.
- In fact, mutable data is a kind of assignment, we have set-car! and set-cdr!
- By introducing those, these axioms no longer tell the whole story
6.IDENTITY=> MAKES CONS HAVE AN IDENTITY
(define a (cons 1 2))
(define b (cons a a))
(set-car! (car b) 3)
=> (car a)
3
=> (cadr b)
3
7.CONS DEFINITION => WHAT IS THE DEFINITION OF CONS, OF THE OLD FUNCTION KIND. ITERMS OF PURELY LAMBDA EXPRESSIONS
(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)))
=> (CAR (CONS 35 47))
(CAR (LAMBDA (M)(M 35 47)))
((LAMBDA (M)(M 35 47))(LAMBDA (A D) A))
((LAMBDA (A D) A) 35 47)
35
- ALONSO CHURCH'S HACK, 1930S, LOGICIAN
8.UPDATE ALONSO CHURCH
(define (cons x y)
(lambda (m)
(m x y
(lambda (n) (set! x n)) // permissions, difference from Alonso Church,
(lambda (n) (set! y n))))) //Has permissions to set Y point to new value)))))
(define (car x)
(x (lambda (a d sa sd) a)))
(define (cdr x)
(x (lambda (a d sa sd) d)))
(define (set-car! x y)
(x (lambda (a d sa sd)(sa y))))
(define (set-cdr! x y) // this y is first percedure's n
(x (lambda (a d sa sd)(sd y))))









网友评论