美文网首页SICP OpenCourse
SICP OpenCourse 4 : L5A-P1-Assig

SICP OpenCourse 4 : L5A-P1-Assig

作者: 牛头酋长 | 来源:发表于2020-08-05 01:59 被阅读0次

SICP OpenCourse (Structure and Interpretation of Computer Programs)

1.POINT: FUNCTIONAL STYLE AND  PROCEDURAL STYLE

    - Object-oriented Style is child of Procedural Style.

    - Two different implementation for the same require, we can get the feeling of the essential of them.

    - Assignment is the core essential of Procedural Style.

2.ASSIGNMENT IS ABOUT TIME. AND TIME MEANS STATE.

<BEFORE>

(SET! <VAR> <VALUE>)

<AFTER>

3.MAKE A EXAMPLE: DEMO TO IMPLEMENT "ADD ONE"

(DEFINE COUNT 1)    //GLOBAL VAR
(DEFINE  (DEMO X)
    (SET! COUNT ( 1 + COUNT))
    ( + X COUNT ))

=> ( DEMO 3)
     5

=> ( DEMO 3)        //BECAUSE COUNT IS 2 NOW
    6

4.DEMO IS NOT FUNCTION. 

    - Same expression(DEMO) different answers.

    - Because different TIME.

    - DEMO IS NOT FUNCTION, DEMO dose not compute a mathematical function.

    - So, not every PROCEDURE is FUNCTION.

    - Time is the judge point: Function don't care about TIME, but DEMO care. What is the name of the new kind of Procedure? State Procedure or some thing else? The answer is ENVIRONMENT MODEL.

5.SUBSTITUTION MODEL  vs ENVIRONMENT MODEL .

    - DEMO is the First place where the substitution model isn't going to work.

    - The substitution model is a STATIC phenomenon, that describes things that are TRUE and not things that CHANGE.

    - Substitution model, which is the core essential concept of Functional Style.

    - Assignment, which is the core behavior of Procedural Style.

    - The different point is about TIME, and TIME means STATE.

    - SERVERLESS vs SERVER, 

    - Our Body => SERVER => TIME=> Substance.

    - Our Thought => SERVERLESS =>TIME UNCORRELATED => Information.

    - The TREE can change to each other freely: Information, Energy , Substance.

    - We can say Functional and Procedural is the same thing, the different is our description that is PERSPECTIVE. AND different perspective means different Interpreter. So, We come back to the Core of this book, The Common perspective is Interpreter.
      

6.TWO DIFFERENT VERSION: FUNCTION VERSION vs IMPERATIVE VERSION

    - Before I give you any understanding of this, this is very bad. Now we've lost our model of computation, pretty soon, I'm going to have to build you a new model of computation. But our play with this, just now, in an informal sense.

    - There ha better be a good reason for it, otherwise just a waste of time and a lot of effort.

- Function Version: Purely function.
(DEFINE  (FACT N)
    (DEFINE  (ITER M I)
        (COND   ((> I N) M)
                        (ELSE  (ITER  (* I M) (+ I 1)))    //COPY THE BODY OF PROCEDURE
    (ITER 1 1))

- Imperative Version:
(DEFINE  (FACT N)
    (LET  ((I 1) (M 1))
        (DEFINE  (LOOP)
            (COND  ((> I N) M)
                (ELSE
                    (SET! M (* I M))    //KEY POINT, DIFFERENCE,NOT COPY, BUT CHANGE.
                    (SET! I (+ I 1))
                    (LOOP))))
    (LOOP)))

    - The substitution model says, you copy the body of the procedure with the arguments substituted for the formal parameters.

    - Seems like essentially the same program, but there are some way of making errors here that didn't exist until today. For example, Interchange those two ASSIGNMENTS , there will be ERROR. Because M upon last value I, because "TIME".

7.DIFFERENCE BETWEEN DEFINE, LET, SET!

    - DEFINE

        -DEFINE is intended for setting something once the first time, for making it, which will be FOREVER that value after that point. => All defines were done at the beginning.

        - Beginning of a Lambda. Beginning of the body of a procedure.

    - LET

        - It sets up a context where I and M are value one and one. That context exists throughout this scope, I never changes because of the LET I gets created because of LET.

        - Origin Show:

            (LET (( var1 e1)(var2 e2)) e3)
            equal=> same expression written in two different ways:
            ((Lambda (var1 var2) e3) e1 e2)

    -What makes the difference between a LET an a DEFINE?

        - A DEFINE is a syntactic sugar, where by, essentially a bunch of variables get created by lets and then set up once.

相关文章

网友评论

    本文标题:SICP OpenCourse 4 : L5A-P1-Assig

    本文链接:https://www.haomeiwen.com/subject/ikogrktx.html