- SICP OpenCourse 5 : L5A-P2~P3-As
- SICP OpenCourse 1 : L1A Overview
- SICP OpenCourse 4 : L5A-P1-Assig
- SICP OpenCourse 9 : L7A-Metacirc
- SICP OpenCourse 13 : L9A-Registe
- SICP OpenCourse 2 : L1B Processe
- SICP OpenCourse 7 : L6A-Stream I
- SICP OpenCourse 15 : L10B-Storag
- SICP OpenCourse 10 : L7B-Metacir
- SICP OpenCourse 11 : L8A-Logic P
SICP OpenCourse (Structure and Interpretation of Computer Programs)
1.POINT: ENVIRONMENT MODEL vs SUBSTITUTION MODEL
2.FREE VARIABLES
(lambda (x) (* x y) //y is free variable
(lambda(y) (( lambda (x)(* x y)) 3)) // scope of y and scope of x.
3.Now we have enough terminology to begin to understand how to make a new model for computation because the key thing going on here is that we destroyed the substitution model, and we now have to have a model that represents the names as referring to places. Because if we are going to change something, then we have a place where it's stored.
4.ENVIRONMENT STRUCTURES
- Tree structure because expression is also a Tree.
- Free Variable will point to the Global frames.

- An environment is a way of doing substitutions virtually. It represents a place where something is stored which is the substitutions that you haven't done. It's a place where everything accumulates, where the name of the variables are associated with the values they have, such that, when you say, what dose this name mean, you look up in an environment.
- So an environment is a FUNCTION, or a table, or something like that. But it's a structured sort of table. It's made out of things called frames. Frames are pieces of environment, and they are chained togeter, in some nice ways, by what's called parent links or something like that.
5.ENVIRONMENT MODEL

- A is (a pointer to) a PROCEDURE OBJECT.
- B is (a pointer to) an environment.
- C is the code of the procedure.
- We're going to have to use this to capture the values of the free variables that occur in the procedure. If a variable occurs in the procedure it's either bound in that procedure or free.
- If it's bound, then the value will somehow be easy to find. It will be in some easy environment to get at.
- If it's free, we're going to have to have something that goes with the procedure that says where we'll go look for its value. => see later util from global frame.
6.AN EXAMPLE: (P 3 4)
(define P (lambda (x y) E)
(P 3 4)

L5A-P3
7.WHY? Why we use Assignment? which destroys most of the interesting mathematical properties of our programs.
- The valuable SCOPE of Assignment Programming. (SERVER)
- The invaluable BORAD of FUNCTIONAL Programming. (SERVERLESS)
8.EXAMPLE MAKE-COUNTER
(DEFINE MAKE-COUNTER
(LAMBDA (N)
(LAMBDA ()
(SET! N(1 + N))
N)))
- THE PICTURE DESCRIPTION:

- There apply the procedure just likes the Java new Object()
9.OBJECT : IT'S ONE CLOCK WORLD VIEW, A PERSPECTIVE, SOME TIME IT WORKS.
- I am an Object, you are an Object. We're individual.
- Now, indeed there are forces that couple us. I'm talking to you and your state changes. I'm looking at you and my state changes. Some of my state variables, a very few of them, there for, are coupled to yours. If you were to suddenly yell very loud, my blood pressure would go up.
- However, and it may not be always appropriate to think about the world as being made out of independent states and independent particles.
- Lost of the bugs that occur in things like quantum mechanics, or the bugs in our minds that occur when we think about things like quantum mechanics, are due the fact that we are trying to think about things being broken up into independent pieces.
- When in fact there's more coupling than we see on the surface, or that we want to believe in, because we want to compute efficiently and effectively. We've been trained to think that way.
10.HOW WOULD WE KNOW IF WE HAD OBJECTS AT ALL?
- How can we tell if we have Objects? => change and compare.
- How do we know if something changed?
-We have to look at it before and after the change.
- The change is an assignment. it's a moment in time.
- I have changed, why am I the same?
- What is the identity of me?
11.ACTION & IDENTITY
- We say that an action A had an effect on an object X (or equivalently, that X was changed by A) if some property P which was true of X before A because false of X after A.
- We say that two objects X and Y. are the same if any action which has an effect on X has the same effect on Y.
12. OBJECT-ORIENTED PROGRAMMING.
- However, Objects are very useful, for intellectual economy.
- We like think about the world is made out of independent Objects with independent local state. We like think that way, although it isn't completely true.
- When we want to make very complicate programs that deal with such a world, if we want those programs to be understandable by us and also be changeable, so that if we change the world we change the program only a little bit, then we want there to be connections, isomorphism, between the objects in the world and objects in our mental model.
- The modularity of the world can give us the modularity in our programming.
- So, we invent things called OBJECT-ORIENTED PROGRAMMING and things like that, to provide us with that power.
- MY UNDERSTAND: OBJECT-ORIENTED and FUNCTIONAL-ORIENTED just like the Wave-particle duality. There are the same thing , just from different perspective. Which is more better depends on your current situation.
13.AN EXAMPLE, PI
Cesaro's methodfor estimating Pi:
Prob(gcd (n1, n2)=1) = 6/(Pi * Pi)
(define (estimate-pi n)
(sqrt (/ 6 (monte-carlo n cesaro))))
(define (cesaro)
(= (gcd (rand)(rand)) 1))
(define (monte-carlo trials experiment)
(define (iter remaining passed)
(cond ((= remaining 0)
(/ passed trials))
((experiment)
(iter (-1 + remaining)
(1 + passed)))
(else
(iter (-1 + remaining)
passed))))
(iter trials 0))
(define rand
(let ((x random-init))
(lambda ()
(set! x (rand-update x))
x)))
14.FUNCTION VERSION WHICH NOT USE THE ASSIGNMENT, WE WILL SEE A PROBLEM.
- Key point is the Random, Random need no same , but Function need return the same value for the same arguments. which called substitution model.
> FUNCTIONAL VERSION:
(define (estimate-pi n)
(sqrt (/ 6 (random-gcd-test n))))
(define (random-gcd-test trials)
(define (iter remaining passed x) //That x is the state of the random number generator=>SEED=>LEAK=>SO, FUNCTION IS NOT FUNCTION.
(let ((x1 (rand-update x)))
(let ((x2 (rand-update x1)))
(cond ((= remaining 0)
(/ passed trials))
((= (gcd x1 x2) 1)
(iter (-1 + remaining)
(1 + passed)
x2))
(else
(iter (-1 + remaining)
passed
x2))))))
>PROBLOM
- The state of the random number generator is no longer confined to the insides of the RANDOM number generator.
- It has leaked out. It leaked out in my procedure .
- That does the Monte Carlo experiment. It leaked out two. Because Cesaro called twice, has to have a different value each time.
- So Cesaro can't be a function either, unless I pass it the SEED of the random number generator.
15. SUMMARY
- My understanding: There was an paradox :
- From OBJECT-ORIENTED PROGRAMMING we can get a better RANDOM number generator.
- It is means , from clock world view , we can get a nondeterminacy maker.
- 越浪越确定,越保守越不确定。 视角倾向性,不等于结果倾向性。甚至两者截然相反。
- OBJECT视角倾向,自己维护一份状态,即,脑中的小世界。反而不容易control。
- FUNCTION视角倾向,无我状态,把自己交给世界,只跟随大世界的状态来行动,即兴的活着,反而很容易control。失控中的控制。
网友评论